douzhanglun4482 2018-07-14 06:51
浏览 65
已采纳

将标签从PHP传递到Chart.js

I'm trying to pass a list of names into the labels section of a Chart.js chart which I'm retrieving from a database with PHP.

In my controller I do

json_encode(array_pluck($var->toArray(), 'name'));

which returns:

"["name1","name2","name3","name4","name5","name6"]"

In the view, I have:

labels: {{ $var }},

and when I view the source, I can see

"name1","name2","name3","name4","name5","name6"

This is causing the chart to fail as it's expecting:

'name1','name2','name3','name4','name5','name6'

I've tried various things such as html_entity_decode, json_decode and htmlspecialchars_decode but not of them seem to do anything.

  • 写回答

1条回答 默认 最新

  • douya5194 2018-07-14 07:05
    关注

    You have to use {!! $assets_by_department_departments !!} - This will prevent Blade from escaping the data.

    See https://laravel.com/docs/5.6/blade#displaying-data for further details :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?