2015-11-02 93 views
1

我正在尝试使用owl-carousel传送带有angularjs的传送带。我希望我的传送带滚动无尽,每当列表完全滚动时加载项目并将查询的元素添加到实际列表中。我的问题是:AngularJS和猫头鹰传送带环境中的数组串联

当我从下一页的控制器获取数据时,我想要合并并联系接收到的项目以合并当前数组并将其呈现在旋转木马的末端,这里是我已经做了:

<data-owl-carousel class="owl-carousel" data-options="{navigation: true, pagination: false, rewindNav : false}"> 
     <div owl-carousel-item="" ng-repeat="item in hmc.ProductData.Products track by $index" class="item"> 
      <a ng-href="/#!//{{Page.Culture+'/product/'+item.id}}"> 
      <div class="telewebion-show-box one-row"> 
       <div class="telewebion-show-box-cover"> 
       <ul> 
        <li>{{::item.title}}</li> 
        <li>{{::item.price}}</li> 
       </ul> 
       </div> 
       <img ng-src="{{::item.picture_path}}" width="220" height="148" alt="" class="img-responsive"/> 
      </div> 
      </a> 
     </div> 
     </data-owl-carousel> 

这里是我的控制器:

hmc.getProducts=function(){ 
    ProductFactory.getProducts(hmc.ProductData.Offset,hmc.ProductData.Limit).then(function(Products){ 
     if(hmc.ProductData.Page==0) 
     { 
     hmc.ProductData.Products[0]=''; 
     } 
     hmc.ProductData.Page++; 
     var tempArray=[]; 
     tempArray.push(Products); 
     console.log(tempArray); 
     hmc.ProductData.Products [0]=hmc.ProductData.Products [0].concat(tempArray[0]); 
     console.log(hmc.ProductData.Products); 
     hmc.ProductData.UpdateInProgress=false; 
    }); 
    } 

,但不接触并合并阵列是行不通的。

回答

0

我只是做了这样的:

hmc.ProductData.Page++; 
     var tempArray=[]; 
     var tempArray2=[]; 
     tempArray.push(AjaxProducts); 
     tempArray2.push(hmc.ProductData.Products); 
     hmc.ProductData.Products= tempArray2[0].concat(tempArray[0]); 
     tempArray.length = 0; 
     tempArray2.length = 0; 

现在的角度NG重复只是重复在一个单一的阵列结构和Ajax追加到该数组的末尾

1

使用tempArray.push(Products);您在阵列tempArray的单个单元格中将单个阵列视为整个变量,但未获得预期结果。你应该叫:

tempArray = tempArray.concat(Products); 

这样你推Products每个元素tempArray。请注意,concat不会直接修改调用数组,这种行为迫使您将其返回值重新分配到原始的tempArray