2015-11-02 91 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