错误解码:TypeError:无法读取未定义的属性“2”
Posted
技术标签:
【中文标题】错误解码:TypeError:无法读取未定义的属性“2”【英文标题】:Error Decode: TypeError: Cannot read property '2' of undefined 【发布时间】:2021-11-29 14:09:02 【问题描述】:我一直在努力理解以下脚本的错误之处。该脚本的目的是每当“individual_client_sheet”中的唯一 ID 与两个工作表中的行中的一个 ID 匹配时删除一行:“clients_database”和“clients_sheet”。到目前为止,代码能够删除每张工作表中的相应行,但错误消息“TypeError:无法读取未定义的属性'2'”不断出现,我无法理解为什么。其次,该脚本不会重置“individual_client_sheet”中的字段,因此在删除记录后它似乎停止工作。这是脚本:
function deleteClientRecord ()
// Get Active Sheets
var ss = SpreadsheetApp.getActiveSpreadsheet();
var shClient = ss.getSheetByName ('individual_client_sheet');
var shData = ss.getSheetByName ('clients_database');
var shClientsList = ss.getSheetByName ('clients_sheet');
// Obtain and verify user response
var ui = SpreadsheetApp.getUi();
var response = ui.alert ('Delete', 'Are you sure you want to remove this record?', ui.ButtonSet.YES_NO);
if (response == ui.Button.NO)
return;
var searchValue = shClient.getRange('AF2').getValue();
var shDataValues = shData.getDataRange().getValues();
var shClientsListValues = shClientsList.getDataRange().getValues();
// Delete record from 'clients_database'
var shDataValuesFound = false;
for (var i = 0; i < shDataValues.length; i++)
var rowValue = shDataValues[i];
if (rowValue[3] == searchValue)
var iRow = i+1;
shData.deleteRow(iRow);
// Delete record from All CLients Sheet
var shClientsListValuesFound = false;
for (var j = 0; i < shClientsListValues.length; j++)
var rowValue2 = shClientsListValues[j];
if (rowValue2[2] == searchValue)
var jRow = j+1;
shClientsList.deleteRow(jRow);
ui.alert('Record deleted for - Client #' + shClient.getRange('AF2').getValue() + '');
// Delete Fields
// Checkboxes
shClient.getRange('Z10:AA13').setValue(false);
shClient.getRange('AP5:AQ5').setValue(false);
// Basic Client Info
shClient.getRange('B5:G5').clearContent(); // Business Name
shClient.getRange('AF2').clearContent(); // Client ID
shClient.getRange('B10').clearContent(); // website
shClient.getRange('B12:B13').clearContent(); // billing add
shClient.getRange('B15:B16').clearContent(); // postal add
shClient.getRange('B18').clearContent(); // primary contact
shClient.getRange('B20').clearContent(); // phone
shClient.getRange('B22').clearContent(); // email
shClient.getRange('B26').clearContent(); // additional info 1
shClient.getRange('B28').clearContent(); // additional info 2
// Client Status
shClient.getRange('AN5:AO5').clearContent(); // client status
shClient.getRange('AP5:AQ5').clearContent().setValue(false); // importance
shClientsListValuesFound = true;
shDataValuesFound = true;
return;
【问题讨论】:
【参考方案1】:我认为是错误行:
for (var j = 0; i < shClientsListValues.length; j++)
应该是j
而不是i
:
for (var j = 0; j < shClientsListValues.length; j++)
【讨论】:
lmao,是的,我刚刚意识到拼写错误:') 谢谢以上是关于错误解码:TypeError:无法读取未定义的属性“2”的主要内容,如果未能解决你的问题,请参考以下文章
我怎样才能摆脱错误-TypeError:无法读取未定义的属性'8'
TypeError:无法读取未定义的属性“集合”这里有啥错误?
jQuery DataTables 错误 - TypeError:无法读取未定义的属性“fnInit”