2014-03-19 96 views
0

下面的函數是一個簡單的Angular.js代碼片段:調用從Angular.js控制器

XApp.controller('ProductsController', function ($scope, GetProductsForIndex, $http) { 
    console.log('Step 1'); 
    var Obj = new Object(); 

    Obj.PAGEINDEX = 1; 
    Obj.PAGESIZE = 25; 
    Obj.SPNAME = "index_get_products"; 
    Obj.PAGECOUNT = null; 
    Obj.COUNTRYCODE = 'in' 

    $scope.data = GetProductsForIndex.query({ parameters : Obj }, function() { 
     console.log($scope.data); 
     $scope.products = $scope.data; 
    }); 

}) 


XApp.factory('GetProductsForIndex', function ($resource) { 
    console.log('Step 2'); 
    return $resource('api/index/:object?type=json', {}, { 'query': { method: 'GET', isArray: true } }); 
}); 

我試圖用http://binarymuse.github.io/ngInfiniteScroll/

在他們的演示這裏http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html他們實現無限滾動調用loadMore()函數。

在我的情況,我想執行下列上滾動:

$scope.data = GetProductsForIndex.query({ parameters : Obj }, function() { 
      console.log($scope.data); 
      $scope.products = $scope.data; 
     }); 

,並增加由1. PageIndex的Obj.PAGEINDEX = 1我應該怎樣做呢?今天是我與Angular.js的第三天。

回答

1

你需要實現這樣的功能loadMore你的控制器內,

XApp.controller('ProductsController', function ($scope, GetProductsForIndex, $http) { 
    function loadData($scope, obj){ 
      $scope.products.push(GetProductsForIndex.query({ parameters : Obj }, function()      {   

      })); 
    } 

console.log('Step 1'); 
    var Obj = new Object(); 
    $scope.products=[]; 
    Obj.PAGEINDEX = 1; 
    Obj.PAGESIZE = 25; 
    Obj.SPNAME = "index_get_products"; 
    Obj.PAGECOUNT = null; 
    Obj.COUNTRYCODE = 'in' 

    loadData($scope, Obj); 
}) 
+0

謝謝,它的工作。 – Monodeep