【问题标题】:ruby pass an array to google javascriptruby 将数组传递给 google javascript
【发布时间】:2018-09-26 16:56:58
【问题描述】:

在我看来我有

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_time" data-google="<%= @google_array %>"></div>

@google_array 正确给出了一个数组数组(在浏览器控制台中检查)

我正在尝试将数组传递给 Google 图表 js 文件

// var dataView = document.getElementById('chart_time');
let dataView = document.querySelector('#chart_time');
let dataGoogle = dataView.getAttribute('data-google')
data.addRows(dataGoogle);

但在浏览器中我得到Error: Argument given to addRows must be either a number or an array

【问题讨论】:

  • 你试过解析它吗? data.addRows(JSON.parse(dataGoogle));从数据属性中得到console.log(dataGoogle)的输出是什么?
  • 如果您将此作为答案,我可以批准它 - 效果很好:)

标签: javascript ruby-on-rails arrays ruby


【解决方案1】:

我猜你应该解析它:

data.addRows(JSON.parse(dataGoogle));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-23
    • 2016-08-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 2011-05-16
    • 2014-05-03
    相关资源
    最近更新 更多