大家好我想尝试将数组传递给js文件,但我有这个错误:
在渲染模板期间抛出异常("注意:数组到字符串转换").
这就是我想要的: data: ['2017/7','2017/8']
所以我这样做(在树枝上): data: '{{ user_month_month }}'
当我vardump user_month_month这是我得到的:
array(2) { [0]=> string(6) "2018-7" [1]=> string(6) "2018-8" }
所以我认为我不会在js部分称它为好,我该怎么办?
如果你想要我的控制器:
public function GraphicShow()
{
$em = $this->getDoctrine()->getManager();
$users = $em->getRepository('AppBundle:User')->countUsers();
$not_logged = $em->getRepository('AppBundle:User')->countNotActiveUsers();
$logged = $em->getRepository('AppBundle:User')->countActiveUsers();
$user_month_months = $em->getRepository('AppBundle:Profile')->countByMonthMonth();
$user_month_totals = $em->getRepository('AppBundle:Profile')->countByMonthTotal();
$array_totals = array();
$array_months = array();
foreach($user_month_totals as $user_month_total) {
$array_totals[] = intval($user_month_total["total"]);
}
foreach ($user_month_months as $user_month_month) {
$array_months[] = $user_month_month["month"];
}
$not_logged_result = $not_logged["number"] / $users["number"] * 100;
$logged_result = $logged["number"] / $users["number"] …Run Code Online (Sandbox Code Playgroud)