如果Smarty传来的变量是字符串时:
- $strData = "abc";
- $this->assign("strData", strData);
JavaScript调用:
- <script type="text/javascript">
- ......
- ......
- let strData = '{$strData}';
- console.log(strData);
- ......
- ......
- </script>
如果Smarty传其他数据时,如数组,需要用json_encode包下:
- $fundXData = [];
- $fundYData = [];
- ......
- ......
- $this->assign("fundXData", json_encode($fundXData));
- $this->assign("fundYData", json_encode($fundYData));
- $this->display("dashboard.html")
JavaScript调用:
- <script type="text/javascript">
- ......
- ......
- xAxis: {
- ......
- data: {$fundXData},
- ......
- }
- ......
- ......
- </script>