我是 Javascript 新手,在访问数组数组中的项目时遇到问题。我正在使用 AngularJs 框架,代码如下:
$scope.db.items4 = [];
var newRow={
ID:0,
action1:[0,0,0,0,0,0,0],
action2:[0,0,0,0,0,0,0]
};
$scope.db.items4.push(newRow);
for (var j = 0; j < 50; j++){
var lastRow=items4.length-1;
var thatDay=ts.items[j].day;
if(items4[lastRow].ID=="0"){
items4[lastRow]=ts.items[j].ID;
items4[lastRow].action1[thatDay]=ts.items[j].action1;
items4[lastRow].action2[thatDay]=ts.items[j].action2;
}else{
if(items4[lastRow].ID==ts.items[j].ID && items4[lastRow].action2[thatDay]=="0") {
items4[lastRow].action1[thatDay]=ts.items[j].action1;
items4[lastRow].action2[thatDay]=ts.items[j].action2;
} else{
var newRow2={
ID:0,
action1:[0,0,0,0,0,0,0],
action2:[0,0,0,0,0,0,0]
};
$scope.db.items4.push(newRow2);
lastRow++;
items4[lastRow]=ts.items[j].ID;
items4[lastRow].action1[thatDay]=ts.items[j].action1;
items4[lastRow].action2[thatDay]=ts.items[j].action2;
}
}
}
当我运行它时,javascript 控制台总是说:
Uncaught ReferenceError: items4 is not defined
但是很明显 items4 在一开始就已经定义了;(任何帮助表示赞赏。