我正在使用Google App Script。
我已经从Google表格中的值创建了下拉框。我的目的是收集数组中的selectedIndex,将它们作为参数发送到后端,并让它们根据参数从同一个Google Sheet中输出一个值。
我能够成功地将下拉框的选定索引数组从html表单传递到后端(code.gs),但是当我尝试使用getRange和selectedindexes获取Google表格中单元格的值时,我总是得到这些错误:
console.log - 在calculateCL上未被捕获(代码:22)
Logger.log - 能够记录单元格的值,但当我“返回PTvalue”时,前端会将其记录为未定义。
请帮忙!
page.html中
//gets selected index from dropdown
var CountryIndex = document.getElementById("menu").selectedIndex;
var CUTypeIndex = document.getElementById("ListCUTyp").selectedIndex;
//pushes indices into array
formArray = [];
formArray.push(CountryIndex);
formArray.push(CUTypeIndex);
//array sent to back end within function calculateCL
//on success of calculateCL, run function CLOutput
google.script.run.withSuccessHandler(CLOutput()).calculateCL(formArray)
//outputs value from GS
function CLOutput(PTvalue){
console.log(PTvalue);
document.getElementById("ListPT").value = PTvalue;
}
code.公司
//gets value of cell based on selected index array
function calculateCL(formArray) {
var PTvalue = sheet.getRange(2+formArray[0], 2+formArray[1]).getValue();
Logger.log(PTvalue);
return PTvalue;
}
你的calculateCL
有参数但似乎你在没有参数的情况下使用它。
google.script.run.withSuccessHandler(CLOutput()).`calculateCL()`
看看你的功能:
function calculateCL(formArray)
这是不正确的:
google.script.run
.withSuccessHandler(CLOutput())
.calculateCL(formArray);
这是一个正确的形式:
google.script.run
.withSuccessHandler(CLOutput)
.calculateCL(formArray)
function CLOutput(PTvalue){
console.log(PTvalue);
document.getElementById("ListPT").value = PTvalue;
}
这也是正确的
google.script.run
.withSuccessHandler(function(PTValue){
console.log(PTvalue);
document.getElementById("ListPT").value = PTvalue;
})
.calculateCL(formArray)