【发布时间】: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