@google_array 正确给出数组的数组(在浏览器控制台中检查) 我正在尝试将数组传递到 Google 图表 js 文件 // var dataView = docume-6ren">
gpt4 book ai didi

javascript - ruby 将数组传递给 google javascript

转载 作者:行者123 更新时间:2023-12-03 02:04:28 27 4
gpt4 key购买 nike

在我看来,我有

<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);

但是在浏览器中我得到错误:给addRows的参数必须是数字或数组

最佳答案

我想你应该解析它:

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

关于javascript - ruby 将数组传递给 google javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49866002/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com