dream12001 2017-06-17 21:23
浏览 55
已采纳

laravel:将对象传递给d3.cal-heatmap

I want to build a data variable containing the number of occurrences of unix datetime values.

i.e.

{1489140000.0: 2, 1487239200.0: 1, 1483524000.0: 2, 1486634400.0: 1, 1490086800.0: 3 }

My error is that on the view I'm getting laravel use of undefined constant datas - assumed 'datas'

public function showStatistics()
{
    $job_post_date = Emploi::where('language', 'EN')->pluck('POSTDATE');
    $unix_time = array();

    for ($i=0; $i < count($job_post_date) ; $i++) { 
        $unix_time[$i] = strtotime($job_post_date[$i]);
    }

    $datas = array_count_values($unix_time);
    $datas = json_encode($datas);

    return view('emploi.stats', ['datas' => $datas]);
}

excerpt of a javascript part in the stats.blade.php

....
var cal = new CalHeatMap();
cal.init({
    itemSelector: "#example-d",
    domain: "month",
  itemName: ["job", "jobs"],
    data:  {!! datas !!},
    start: thisMonth.SubtractMonth(5),
    cellSize: 12,
    cellPadding: 5,
    ....

I'm getting an error in the template on: {{ datas }}

  • 写回答

1条回答 默认 最新

  • dongluyi5123 2017-06-17 21:26
    关注

    Use

    data:  {!! $datas !!}
    

    instead of

    data:  {!! datas !!}
    

    You missed the dollar sign, which makes PHP assume it's a constant (which you don't declare).

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

报告相同问题?

悬赏问题

  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件