dousao8152 2015-08-13 10:43
浏览 96
已采纳

将数据从Controller传递给JavaScript

I want to pass data from my Controller to a JavaScript that handles a Google Bar Chart.

composer

$tmp = 6;
return view('pages.template', ['tmp' => $tmp]);

from my template.blade.php I call the Google Chart

<div id="chart_div"></div>

.js file:

var tmp = 6;
var tmp2 = parseInt('{!! $tmp !!}');

var data = google.visualization.arrayToDataTable([
    ['comment1', 'comment2'],
    ["- 6 days", tmp],
    ["- 5 days", tmp2],
    ["- 4 days", 31],
    ["- 3 days", 12],
    ["- 2 days", 10],
    ["- 1 day", 3],
    ["today", 4]

the 2nd bar from Google-Bar-Chart is blank .... enter image description here

But there should be displayed my variable.

How do I solve this issue?

  • 写回答

4条回答 默认 最新

  • dongqindan4406 2015-08-13 11:14
    关注

    Just replace :

    var tmp2 = parseInt('{!! $tmp !!}');
    

    By :

    var tmp2 = parseInt(<?php echo $tmp; ?>);
    

    And it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料