Javascript 从Google工作表到Web应用程序显示匹配值时出错
嘿,当用户输入一个特定的代码号时,我试图显示Google工作表中的一行值。但我的.gs中有个错误: TypeError:codeList.IndexOf不是函数 我的控制台中的错误: 无计可施 以下是我的.html代码:Javascript 从Google工作表到Web应用程序显示匹配值时出错,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,嘿,当用户输入一个特定的代码号时,我试图显示Google工作表中的一行值。但我的.gs中有个错误: TypeError:codeList.IndexOf不是函数 我的控制台中的错误: 无计可施 以下是我的.html代码: document.getElementById("codeInput").addEventListener("input",getData); function getData(){ var code = document.g
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';
}
}
非常感谢您的回复。提前谢谢你 此
var位置=codeList.IndexOf(代码)
应该这样写var position=codeList.indexOf(code)代码>案例在谷歌应用程序脚本和JavaScript中很重要。天哪,这只是案例的问题,哈哈,现在错误消失了。非常感谢。哦,对不起,我会再发一张。。谢谢