gpt4 book ai didi

javascript - 将数组从 google 脚本返回到网站中的函数时出错

转载 作者:行者123 更新时间:2023-11-28 15:36:14 25 4
gpt4 key购买 nike

当调用 update 时,它​​会运行一个名为 update 的脚本,如以下代码片段所示:

在 HTML 中:

function updDate(date){
console.log("update called");

google.script.run.withSuccessHandler(myReturnFunction).updDate(date);
//Crossover.libTest();
console.log("crossover should have been called");

}
function myReturnFunction(garbage){

console.log("Returned: "+ garbage);

/*for (var i = 0; i < whatGotReturned.length; i++) {
document.getElementById("field_"+[i]).innerHTML = whatGotReturned[i];
}*/
}

在 Google 脚本中:

function updDate(date){

var searchString = date;
var s2 = SpreadsheetApp.openById("0AnDrS3YbyWoLdC15aktnMTluUkQ3dWhNTFlyQXBPOFE");
var data = s2.getActiveSheet().getDataRange().getValues();


var k;


for (var i in data) {
for (var j in data[i]) {
if (i !=0){
if(data[i][j] != ""){
if(j == 4){
var ssDate = Utilities.formatDate(data[i][j], "GMT", "MM/dd/yyyy");

if(date == ssDate){
k= i
var p = data[i].length


}//conclude if
}//conclude if (j==4)

}//conclude if(data[i][j] != "")
}//conclude if (data[i][j] != "")
} //conclude for (var j in data[i])
}//conclude for (var i in data)


//Logger.log("K is: "+k)
var valuesToSnd = new Array();

var q = 1
while (q <= p){


//if(data[k][q] !=""){
valuesToSnd[q] = data[k][q];
//document.getElementById("field_"+[q]).innerHTML = data[k][q];

//}


q++

}
Logger.log("Values to Send: "+valuesToSnd);
return valuesToSnd;


}

谷歌脚本将像它应该的那样记录数组:

[14-08-26 08:47:03:950 EDT] Values to Send: ,BABS only at AFM,,BABS,Fri Aug 08 2014 00:00:00 GMT-0400 (EDT),No Unload Necissary,https://docs.google.com/forms/d/1yBiXtjTpXs85BNs5Lsj0zGQtDtxghm6-e2lRebB4saw/viewform?edit=ChM1NzYwNDkwNTY0Nzg2NjY5MTI4EJKj-OTR3ejNhwE,,https://docs.google.com/document/d/15f2HjJjNTxjlLZOkB2BOe8nY9ZlImmaAaSSnhViAa4I/edit,,Thu Aug 07 2014 15:30:00 GMT-0400 (EDT),Sat Dec 30 1899 14:30:00 GMT-0500 (EST),Sat Dec 30 1899 15:00:00 GMT-0500 (EST),Sat Dec 30 1899 18:45:00 GMT-0500 (EST),5 Ton 35 ,No,No,,,,,All Singers,Not needed,,Needed,Needed,,,,https://docs.google.com/spreadsheet/ccc?key=0AnDrS3YbyWoLdDdSel9RVVNVMGhDakwxMmdueGc4WGc&usp=drive_web#gid=4,,No,AFM,https://www.mediafire.com/folder/dp788cvtbexsf/,

脚本运行后的某个地方,控制台返回此错误:

Uncaught ScriptError: The script completed but the returned value is not a supported return type.

代码是否有问题,或者数组中是否存在该函数不“喜欢”的字符?

谢谢

洛伦

这有效:

  var valuesToSnd = new Array();

var q = 0
while (q <= p){

//if(q!=0){

if(data[k][q] !=""){

if (q==11){
var trudeptTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = trudeptTime;
}
else if(q==12){

var lITime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = lITime;
}
else if (q==13){
var sCTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = sCTime;
}else{

valuesToSnd[q] = q+ ": "+ data[k][q];
}


}else{

//valuesToSnd[q]= q + "Nothing";
}
/*}else{
valuesToSnd[q]= q+ ": "+ data[k][q];
}*/
q++

}
Logger.log("Values to Send: "+valuesToSnd);
return valuesToSnd;

}

这不会:

  var valuesToSnd = new Array();

var q = 0
while (q <= p){

//if(q!=0){

if(data[k][q] !=""){

if (q==11){
var trudeptTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = trudeptTime;
}
else if(q==12){

var lITime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = lITime;
}
else if (q==13){
var sCTime = Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "HH:mm");
valuesToSnd[q] = sCTime;
}else{

valuesToSnd[q] = data[k][q];
}


}else{

//valuesToSnd[q]= q + "Nothing";
}
/*}else{
valuesToSnd[q]= q+ ": "+ data[k][q];
}*/
q++

}
Logger.log("Values to Send: "+valuesToSnd);
return valuesToSnd;

}

下面的一些评论是经过一两次调整后的日志:

14-08-27 12:51:51:572 EDT] k:  26 q:  0Timestamp data:  Mon Jul 14 2014 11:08:15 GMT-0400 (EDT)
[14-08-27 12:51:51:573 EDT] k: 26 q: 1Gig Name data: BABS only at AFM
[14-08-27 12:51:51:573 EDT] k: 26 q: 2Program Name data:
[14-08-27 12:51:51:573 EDT] k: 26 q: 3Groups Involved data: BABS
[14-08-27 12:51:51:574 EDT] k: 26 q: 4Gig Date data: Fri Aug 08 2014 00:00:00 GMT-0400 (EDT)
[14-08-27 12:51:51:574 EDT] k: 26 q: 5Notes data: No Unload Necissary
[14-08-27 12:51:51:574 EDT] k: 26 q: 6Gig Coordination Form Link data: https://docs.google.com/forms/d/1yBiXtjTpXs85BNs5Lsj0zGQtDtxghm6-e2lRebB4saw/viewform?edit=ChM1NzYwNDkwNTY0Nzg2NjY5MTI4EJKj-OTR3ejNhwE
[14-08-27 12:51:51:575 EDT] k: 26 q: 7Announcer Name data:
[14-08-27 12:51:51:575 EDT] k: 26 q: 8Program Notes Link data: https://docs.google.com/document/d/15f2HjJjNTxjlLZOkB2BOe8nY9ZlImmaAaSSnhViAa4I/edit
[14-08-27 12:51:51:575 EDT] k: 26 q: 9Jump to page data:
[14-08-27 12:51:51:576 EDT] k: 26 q: 10Truck Load data: Thu Aug 07 2014 15:30:00 GMT-0400 (EDT)
[14-08-27 12:51:51:576 EDT] k: 26 q: 11Truck Departure Time data: Sat Dec 30 1899 14:30:00 GMT-0500 (EST)
[14-08-27 12:51:51:577 EDT] k: 26 q: 12Load In Time data: Sat Dec 30 1899 15:00:00 GMT-0500 (EST)
[14-08-27 12:51:51:578 EDT] k: 26 q: 13Sound Check Time data: Sat Dec 30 1899 18:45:00 GMT-0500 (EST)
[14-08-27 12:51:51:579 EDT] k: 26 q: 14Trucks to be used data: 5 Ton 35 
[14-08-27 12:51:51:579 EDT] k: 26 q: 15LRS Support Required data: No
[14-08-27 12:51:51:579 EDT] k: 26 q: 16LRS Request submitted data: No
[14-08-27 12:51:51:580 EDT] k: 26 q: 17Date Request submitted to Band VCO/VNCO data:
[14-08-27 12:51:51:580 EDT] k: 26 q: 18LRS Confirmation Number data:
[14-08-27 12:51:51:581 EDT] k: 26 q: 19Unload Truck data:
[14-08-27 12:51:51:581 EDT] k: 26 q: 20Jump to page data:
[14-08-27 12:51:51:581 EDT] k: 26 q: 21BABS Crew Members data: All Singers
[14-08-27 12:51:51:581 EDT] k: 26 q: 22BABB Crew Members data: Not needed
[14-08-27 12:51:51:582 EDT] k: 26 q: 23Jump to page data:
[14-08-27 12:51:51:582 EDT] k: 26 q: 24Input List data: Needed
[14-08-27 12:51:51:583 EDT] k: 26 q: 25Pack List data: Needed
[14-08-27 12:51:51:583 EDT] k: 26 q: 26Pack list Link (If Applicable) data:
[14-08-27 12:51:51:583 EDT] k: 26 q: 27Singers Standing arrangment data:
[14-08-27 12:51:51:583 EDT] k: 26 q: 28Jump to page data:
[14-08-27 12:51:51:584 EDT] k: 26 q: 29Input List Link (if Applicable) data: https://docs.google.com/spreadsheet/ccc?key=0AnDrS3YbyWoLdDdSel9RVVNVMGhDakwxMmdueGc4WGc&usp=drive_web#gid=4
[14-08-27 12:51:51:584 EDT] k: 26 q: 30 data:
[14-08-27 12:51:51:584 EDT] k: 26 q: 31Singers Stands required data: No
[14-08-27 12:51:51:585 EDT] k: 26 q: 32Gig Location data: AFM
[14-08-27 12:51:51:585 EDT] k: 26 q: 33Media Link data: https://www.mediafire.com/folder/dp788cvtbexsf/

最佳答案

我认为日期/时间值导致了错误。

考虑将所有日期/时间更改为字符串或 JSON:

if (data[k][q] instanceof Date) data[k][q] = data[k][q].toJSON();

这似乎对我有用。

关于javascript - 将数组从 google 脚本返回到网站中的函数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25506285/

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