[英]SyntaxError: expected expression, got '&'
I do a loop on my controller: 我在控制器上执行循环:
$events = '[';
while ($init->format('w') != $agenda->day){
$events = $events . "{title: 'test', start: '" . $init->format('Y-m-d') . "'},";
$init->add(new DateInterval('P1D'));
}
$events = $events . ']';
the result is this string: 结果是这个字符串:
[{title: 'test', start: '2018-09-15'},{title: 'test', start: '2018-09-16'},]
On my blade page, I have a script
to generate a fullcalendar and I put the code on it: 在我的刀片页面上,我有一个
script
来生成一个全日历,并将代码放到上面:
events:
{{$eventos}},
But inside the script
my code change to: 但是在
script
我的代码更改为:
[{title: 'test', start: '2018-09-15'},{title: 'test', start: '2018-09-16'},]
and I receive the error: 我收到错误:
SyntaxError: expected expression, got '&'
SyntaxError:期望的表达式,得到了“&”
How to do the script
read '
rather than '
如何将
script
读为'
而不是'
? ?
Instead of creating the json string in your loop, define an array to pass to the view. 而不是在循环中创建json字符串,而是定义一个数组以传递给视图。
$events = [];
while ($init->format('w') != $agenda->day){
$events[] = [
'title' => 'test',
'start' => $init->format('Y-m-d')
];
$init->add(new DateInterval('P1D'));
}
Then in the view file use the @json blade directive to output your array as json. 然后在视图文件中使用@json blade指令将数组输出为json。
events: @json($events);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.