我正在尝试从 Google 电子表格中提取数据来填充一些 div。然而,总是失败。
这是我的 JavaScript:
$(function() {
google.script.run.withFailureHandler(alert("It is not working")).withSuccessHandler(build_req_view).getRequisitionEntries();
});
function build_req_view(things) {
var list = $('#div-content-req-view-body');
list.empty();
for (var x = 1; x < things.length; x++) {
list.append("<div class=\"req-view-item\">");
list.append("<div class=\"req-view-item-header\">");
list.append("REQUISITION NUMBER - STATUS");
list.append("</div>");
list.append("</div>");
}
}
我的 HTML 看起来像这样:
<div id="div-content-req-view" class="div-content-container">
<div id="div-content-req-view-header" class="div-content-header">
View Requisitions
</div>
<div id="div-content-req-view-body" class="div-content-body">
Loading...
</div>
</div>
我的 Google Apps 脚本是这样的:
function getRequisitionEntries() {
var data = SpreadsheetApp.openById(ENTRY).getSheetByName("requisitions").getDataRange().getValues();
Logger.log(data);
return data;
}
无论出于何种原因,
getRequisitionEntries()
功能不起作用,因此总是提示警报。我很困惑为什么这不起作用。我在同一个项目中的许多其他元素基本上使用了相同的 HTML、JS、GS 代码。但是,这似乎无法与 successhandler
一起运行。
我想知道这是否是因为我尝试提取的数据比我在项目中使用的其他 SpreadsheetApp 调用具有更多的列。所有正确的 ID 都正确通过,因为我已检查并仔细检查过。
可能是什么问题?
根据 google.script.run 类的详细文档,“如果您尝试传递除表单之外的日期、函数、DOM 元素或其他禁止类型,包括对象或数组内的禁止类型,请求将失败。” –
卡尔_S
https://developers.google.com/apps-script/guides/html/reference/run#detailed-documentation