我试图根据工作表单元格中的值显示从Google到的数据。因此,当值为“是”时,用户可以看到表数据,否则会显示拒绝警报。为了说明这一点,下面是流程:
< code >G29
我尝试使用我的代码,如果值不是“是”,它可能会警告拒绝,但是如果值是“是”,则会得到一个错误:
Uncaught :无法读取属性'10‘的null
有办法解决吗?(欢迎您的答复:)
下面是我的Javascript代码示例:
function submitCode(){
var code = document.getElementById("codeInput").value;
google.script.run.withSuccessHandler(view).checkTable(code);
}
function view(array){
if (typeof array === 'string') {
alert(array);
}else{
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);
}
}下面是我的.gs代码示例:
function checkTable(code){
var url = PropertiesService.getScriptProperties().getProperty('url');
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Sheet1");
var data = ws.getRange(5, 1, ws.getLastRow()-1, 4).getValues();
var codeList = data.map(function(r){return r[0].toString(); });
var position = codeList.indexOf(code);
var approval1 = data.map(function(r){return r[1]; });
var approval2= data.map(function(r){return r[2]; });
if(approval1[position] == "YES"){
getTable(code);
}else if(approval2[position] == "YES"){
getTable(code);
}else{
return "Sorry You cannot see the table";
}
}
function getTable(code){
var url = PropertiesService.getScriptProperties().getProperty('url');
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Sheet1");
var data = ws.getRange(5, 1, ws.getLastRow()-1, 6).getValues();
var codeList = data.map(function(r){return r[0].toString(); });
var position = codeList.indexOf(code);
var things1= data.map(function(r){return r[3]; });
var things2= data.map(function(r){return r[4]; });
var things3= data.map(function(r){return r[5]; });
var array = [things1[position], things2[position], things3[position]];
}发布于 2020-08-12 03:32:52
这个修改怎么样?
修改要点:
在您的脚本中,在Google脚本端,
getTable()和checkTable()的值,而return "Sorry You cannot see the table";返回。我认为这就是您出现问题的原因。tbody.appendChild(row)。这样,就没有显示创建的元素。当以上要点反映到您的脚本中时,如下所示。
修改脚本:
Google脚本端:
function checkTable(code){
var url = PropertiesService.getScriptProperties().getProperty('url');
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Sheet1");
var data = ws.getRange(5, 1, ws.getLastRow()-1, 4).getValues();
var codeList = data.map(function(r){return r[0].toString(); });
var position = codeList.indexOf(code);
var approval1 = data.map(function(r){return r[1]; });
var approval2= data.map(function(r){return r[2]; });
if(approval1[position] == "YES" || approval2[position] == "YES"){ // Modified
return getTable(code); // Added
}else{
return "Sorry You cannot see the table";
}
}
function getTable(code){
var url = PropertiesService.getScriptProperties().getProperty('url');
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Sheet1");
var data = ws.getRange(5, 1, ws.getLastRow()-1, 6).getValues();
var codeList = data.map(function(r){return r[0].toString(); });
var position = codeList.indexOf(code);
var things1= data.map(function(r){return r[3]; });
var things2= data.map(function(r){return r[4]; });
var things3= data.map(function(r){return r[5]; });
var array = [things1[position], things2[position], things3[position]];
return array; // Added
}HTML & Javascript端
function view(array){
if (typeof array === 'string') {
alert(array);
}else{
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); // Added
}
}https://stackoverflow.com/questions/63369148
复制相似问题