【发布时间】:2016-08-16 10:57:53
【问题描述】:
我对我的 code.gs 文件进行了相当简单的调用,以获取工作表中的一些数据。我从一个 html 文件调用这个函数来填充一个下拉列表。所以:
代码.gs
function getTheStuffINeed() {
// Get data from sheet
var ss = SpreadsheetApp.openById("ss_id");
var sheet = ss.getSheetByName("sheetname");
var myStuff = sheet.getRange(2, 1, sheet.getLastRow()-1, 3).getValues();
Logger.log(Array.isArray(myStuff)); // true.
Logger.log(myStuff); // [[id1, aVal, aSecondVal], [id2, AnotherVal, anotherSecondVal]]
return myStuff ; // An array of arrays
}
index.html
<script>
// get data
var myStuff= <?= getTheStuffINeed() ?>;
console.log(Array.isArray(myStuff)); // false
console.log(myStuff); // id1, aVal, aSecondVal, id2, AnotherVal, anotherSecondVal, etc
</script>
当我的结果到达 html 页面时,它不再是一个数组数组,而是一个逗号分隔值的字符串。
谁能解释一下这里发生了什么,以及如何解决?谢谢。
【问题讨论】:
标签: javascript google-apps-script google-sheets