2
我試着在樹枝中回顯json編碼字符串。這是我的代碼,回聲json在symfony樹枝中編碼的字符串
控制器
$jsonArray = array(
array(
'label' => 'CN Clogs Beach',
'data' => 5
),
array(
'label' => 'Prod my prod',
'data' => 5
),
array(
'label' => 'New Pro',
'data' => 3
)
);
$jsonArray = json_encode($jsonArray);
return $this->render("EagleAdminBundle:dashboard:index.html.twig", array(
'jsonArray' => $jsonArray
));
這是枝文件
<script type="text/javascript">
var data = {{ jsonArray }};
</script>
,而不是領JSON數組我得到這樣的事情,
var data = [{"label":"CN Clogs Beach","data":5},{"label":"Prod my prod","data":5},{"label":"New Pro","data":3}];