所以只是调试别人的代码,我已经修复了 Firefox 中的所有内容,现在又修复了 Chrome,但是当我尝试选择一个选项来选择所有子节点并打开它们的相关图表时,我收到了一个奇怪的错误:
未捕获的类型错误:无法调用未定义的方法“substr”
我知道问题是(显然)这一行:
var graph={id:seqId,entityName:flags[6].substr(1).substr(0,flags[6].length-2),entity:flags[5].substr(1).substr(0,flags[5].length-2),idCounter:flags[4],counterName:flags[3].substr(1).substr(0,flags[3].length-2),ivmanager:flags[7].substr(1).substr(0,flags[7].length-2),chart:null,pointsToShowX:null,borneInf:null,unite:"",idInstance:flagsInstance[2].substr(1).substr(0,flagsInstance[2].length-2),instanceName:flagsInstance[3].substr(1).substr(0,flagsInstance[3].length-2),listPdsNull:new Array(), countInstance:idTreeview+"_"+i, countGraph:-1};
但我不知道为什么这会导致错误,因为一切对我来说都是正确的?!substr 在函数之前和之后被无数次使用,所以我不知道为什么 Chrome 会向我抛出这个错误。
完整的功能如下。我相信问题出在第二部分。
function loadGraphs(idTreeview,idSelectGraph)
{
var count=0;
var fn=$('#'+idSelectGraph)[0].attributes[1].value;
fn=fn.substr(12).substr(0,fn.length-2);
var flags=fn.split(new RegExp(","));
var data='';
var idInstanceTreeview = idTreeview;
if($('#counterTreeviewUL'+idInstanceTreeview).length == 0)
{
var fnInstance=$('#'+idSelectGraph)[0].attributes[1].value;
var flagsInstance=fnInstance.split(new RegExp(","));
var graph = {
id: seqId,
entityName: flags[6].substr(1).substr(0, flags[6].length - 2),
entity: flags[5].substr(1).substr(0, flags[5].length - 2),
idCounter: flags[4],
counterName: flags[3].substr(1).substr(0, flags[3].length - 2),
ivmanager: flags[7].substr(1).substr(0, flags[7].length - 2),
chart: null,
pointsToShowX: null,
borneInf: null,
unite: "",
idInstance: flagsInstance[2].substr(1).substr(0, flagsInstance[2].length - 2),
instanceName: flagsInstance[3].substr(1).substr(0, flagsInstance[3].length - 2),
listPdsNull: new Array(),
countInstance: idTreeview + "_" + i,
countGraph: -1
};
seqId++;
graphs[graphsLastId]=graph;
graphsLastId++;
}
else
{
for(var i=0;i<$('#counterTreeviewUL'+idInstanceTreeview)[0].children.length;i++)
($('#counterTreeviewUL'+idInstanceTreeview)[0].children[i].children[0].checked)?++count:count;
if ($('#counterTreeviewUL'+idInstanceTreeview)[0].children.length == count)
{
$('#'+idSelectGraph)[0].checked=true;
$('#'+idSelectGraph)[0].indeterminate=false;
}
else if (count==0)
{
$('#'+idSelectGraph)[0].checked=true;
$('#'+idSelectGraph)[0].indeterminate=false;
}
else
{
$('#'+idSelectGraph)[0].checked=true;
$('#'+idSelectGraph)[0].indeterminate=false;
}
for (var i=0;i<$('#counterTreeviewUL'+idTreeview)[0].children.length;i++)
{
if (!$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked)
{
$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked=true;
var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value;
fnInstance=fnInstance.substr(15).substr(0,fnInstance.length-2);
var flagsInstance=fnInstance.split(new RegExp(","));
var graph = {
id: seqId,
entityName: flags[6].substr(1).substr(0, flags[6].length - 2),
entity: flags[5].substr(1).substr(0, flags[5].length - 2),
idCounter: flags[4],
counterName: flags[3].substr(1).substr(0, flags[3].length - 2),
ivmanager: flags[7].substr(1).substr(0, flags[7].length - 2),
chart: null,
pointsToShowX: null,
borneInf: null,
unite: "",
idInstance: flagsInstance[2].substr(1).substr(0, flagsInstance[2].length - 2),
instanceName: flagsInstance[3].substr(1).substr(0, flagsInstance[3].length - 2),
listPdsNull: new Array(),
countInstance: idTreeview + "_" + i,
countGraph: -1
};
seqId++;
graphs[graphsLastId]=graph;
graphsLastId++;
}
}
}
graphsToLoad=false;
updateAllGraphs();
loading=false;
if($('#counterTreeviewUL'+idInstanceTreeview).length == 0)
{
if($('#'+idSelectGraph)[0].checked)
{
countSelectedGraphs(graphsLastId, flags[5].substr(1).substr(0,flags[5].length-2), 0);
}
else
{
countSelectedGraphs(graphsLastId, flags[5].substr(1).substr(0,flags[5].length-2), 0);
}
}
else
{
countSelectedGraphs(graphsLastId, flags[5].substr(1).substr(0,flags[5].length-2), 0);
}
}
任何有关导致此看似随机错误的原因的见解都将不胜感激,因为我在网上找不到太多关于此错误的信息(我看到它发生的情况与我的情况完全不同),谢谢!