Javascript数组推送没有给出期望的结果

时间:2013-10-26 11:39:45

标签: javascript

我遇到的问题是,当我将项目推入或取消对阵列时,它们会被自动分组,非常奇怪:我猜测我的循环没有很好地组合在一起,或多或少我正在尝试。非常感谢。

   var i;
   var anObject:/*is created dynamically in a loop for instance I load random images
   and push into  ' myArray'. My myaArray should
   look like this:["image1,image3,image2,image3,image2] but instead 
   im getting:["image1,image3,image3,image2,image2] there grouping up for some reason,
   But i dont   want them too*/


  var BookH = []; 

  function create(){ 
  for (var i=0; i<10; i++){
   var object;
    var tempObject;
    var loader = new THREE.OBJMTLLoader();
    loader.load( 'mod/'+mysqlVars[i].Format+'.obj','mod/bookH.mtl') ;
    loader.addEventListener( 'load', function ( event ) {
           object = event.content;
           for(k in object.children){
               object.children[k].castShadow = true;
               object.children[k].receiveShadow = false;

           } 

          tempObject = object.clone();
          BookH.push(tempObject);
          console.log('mod/'+mysqlVars[9].Format);
          if(BookH.length == 10){
               populate();
           }
         });
    }

    /////////counter loop///
}

0 个答案:

没有答案