Fra*_*tes 2 javascript google-apps-script
菜鸟,过去一周我一直遇到这个问题,我不明白为什么 javascript 不会看到 code.gs 的返回值,因为我有相同的代码但不同的函数按预期工作。
是否有原因导致 Logger.log 中的日志值下方的 code.gs 函数意味着它有数据要返回,但 javascript 不会获取任何值并在警报中给我一个“null”?
代码.gs
function getInvoicesForID(studentAltID) {
var invoicesForID = [];
//get general invoices sheet and values
var sInvoices = ss.getSheetByName("Invoices");
var dataInvoices = sInvoices.getDataRange().getValues();
//get balance info for id
for(var i = 0; i < dataInvoices.length; i++){
if(dataInvoices[i][4]==studentAltID){
invoicesForID.push([dataInvoices[i][0],dataInvoices[i][1],dataInvoices[i][2],dataInvoices[i][3]]);
break;
}
}
Logger.log("invoicesForID = " + invoicesForID);
return invoicesForID;
}
Run Code Online (Sandbox Code Playgroud)
javascript.html
document.getElementById("btnsearchInvPayBalforStudentID").addEventListener("click",searchInvPayBalforStudentID);
//function to look for Payments, Invoices and Balance
function searchInvPayBalforStudentID()
{
try{
//get the id
var stID = document.getElementById("txtStudentID").value;
google.script.run.withSuccessHandler(getInvoices)
.getInvoicesForID(stID);
}catch(e){
alert(e);
}
}
function getInvoices(stIDInvData) {
try{
alert(stIDInvData);
}catch(e){
alert(e);
}
}
Run Code Online (Sandbox Code Playgroud)
当代码执行并检查日志时,我确实看到来自 gs 函数的数据,如下所示,这是传递的 StudentAltID 的预期数据的数据
[19-07-04 22:12:13:491 EDT]发票ForID = 2019 年 1 月 31 日星期四 00:00:00 GMT-0500 (EST),34073,Matricula 2019,298854
我缺少什么?
先感谢您 :)
更新:
我包含了事件处理程序(单击时的按钮),我检查了语法错误和括号错配,但找不到问题
这是该项目的链接,其中包含我在帖子中清理的更多项目,希望它可能有所帮助
谢谢
(……光束照射进来,天使在背景中齐声唱着哈利路亚……)
我在这里找到了答案: Unable to return Array [Google apps script] from @VishnarTadeleratha
事实证明,我无法在数组中传递日期,这正是我返回的数组中的项目之一:谷歌说:“参数:...如果您尝试传递日期、函数、DOM 元素,则请求会失败表单或其他禁止类型,包括对象或数组内的禁止类型...来源:https ://developers.google.com/apps-script/guides/html/reference/run
一旦我从返回数组中删除该项目,javascript 得到的值就不同于 null..万岁。
如果我仍然需要在数组中传递日期(我这样做了),@VishnarTadeleratha 还建议将该变量转换为字符串,瞧……我的长屁股问题现在已经解决了……终于我可以继续前进了……干杯
归档时间: |
|
查看次数: |
1497 次 |
最近记录: |