簡體   English   中英

javascript:訪問array的array內部的項目

[英]javascript: access the item inside array of array

我是Java語言的新手,在訪問array數組中的項目時遇到問題。 我正在使用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 

但是很明顯,一開始就定義了item4; (任何幫助表示贊賞。

如果您想簡化它,請將第一行更改為:

var item4 = $scope.db.items4 = [];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM