简体   繁体   中英

Javascript Multidimensional Arrays - undefined error

Luckily this forum exist, so of I go with posting a tricky question to the great masters... I am working on a program that loads multiple images in a page. The program does what it suppose to do, the problem is that I am getting an undefined error , and I don't have any idea what is the cause, the program is the following:

var imagesList = [['aaa','sss'], ['bbb','ttt']];
putImages(imagesList);
function putImages(imagesList){
  var i = 0;
  if ($(imagesList).length > 0){ 
    LoadImage(i, imagesList);
  }
}

function LoadImage(i, imagesList){
  var ele = imagesList[i][0],
    name = imagesList[i][1];    
  if(i < $(imagesList).length){
    var curr = $('<li id="pic-'+ i +'"><div>'
                         + name +'</div>').addClass("loading");
    $(curr).appendTo(".photos");
    var image = new Image();
    $(image).load(function(){       
        $(this).appendTo("#pic-" + i);  
        $(curr).removeClass("loading"); 
        LoadImage(i+1, imagesList );
    }).error(function(){
    }).attr("src", ele);
  }
}

I tried to use the advice from this link JavaScript Multidimensional Arrays , but it is just what ever I try i keep getting this error in Firefox, the other browsers seem to be ok.

Thanks a lot in advance.

I'm not sure what the exact problem is, but it could be related to the fact that you pass the array to jQuery. There is not need for that.

Instead of $(imagesList).length , write imagesList.length .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM