assign("strData", strData); JavaScript调用: ...... .-6ren">
gpt4 book ai didi

PHP笔记-JavaScript中使用Smarty变量

转载 作者:知者 更新时间:2024-03-13 03:44:44 29 4
gpt4 key购买 nike

如果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>

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com