嘿,当用户输入特定的代码编号时,我正在尝试从 Google 表格中显示一行值。但我的 .gs 出现错误:
TypeError:codeList.IndexOf 不是函数
我的控制台中出现错误:
在 getTable 未捕获
这是我的 .html 代码:
document.getElementById("codeInput").addEventListener("input",getData);
function getData(){
var code = document.getElementById("codeInput").value;
if(code.length === 5){
google.script.run.withSuccessHandler(view).getTable(code);
}
}
function view(array){
var tbody = document.getElementById("table-body");
var row = document.createElement("tr");
var col1 = document.createElement("td");
col1.textContent = array[0];
var col2 = document.createElement("td");
col2.textContent = array[1];
var col3 = document.createElement("td");
col3.textContent = array[2];
row.appendChild(col1);
row.appendChild(col2);
row.appendChild(col3);
tbody.appendChild(row);
}
这是我的 .gs 代码:
function getTable(code){
var url = "https://docs.google.com/spreadsheets/d/1Nh-CCXayaQ8YFuxV76MGnWiAF2rgcxf5bCJwJWvy_-s/edit#gid=0";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("IPP Gol I-III");
var data = ws.getRange(2, 1, ws.getLastRow()-1, 4).getValues();
var codeList = data.map(function(r){return r[1]; });
var submissionList = data.map(function(r){return r[0]; });
var nameList = data.map(function(r){return r[2]; });
var emailList = data.map(function(r){return r[3]; });
var position = codeList.IndexOf(code);
var array = [submissionList[position],nameList[position],emailList[position]];
if(position > -1){
return array;
}else{
return 'Unavailable';
}
}
您的回复将不胜感激。先感谢您!
汪汪一只猫
相关分类