我是新来的Javascript和我有一个问题,以访问阵列内的数组内的项目。 我使用AngularJs框架,这里是代码:javascript:访问阵列内的项目
$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已开始被定义; (任何帮助表示赞赏
如果缓存'items4 [LASTROW]'你会让代码1000次清洁 – elclanrs 2013-04-24 20:59:06
不,'items4'没有被定义,'$ scope.db.items4'已经被使用。 – 2013-04-24 21:00:59
是的,它看起来像你实际上从来没有定义过items4 ...这就像'var items4 = $ scope.db .items4;' – Timmerz 2013-04-24 21:02:02