离子框架无限滚动与http获取数据

Far*_*war 2 javascript wordpress jquery angularjs ionic-framework

我刚刚开始使用离子框架(辉煌),我是棱角分明的新手.我有一个Web服务正在运行,应用程序应该加载数据.我已经设法检索数据,放,wordpress rest api正在以页面的形式发送数据,我不知道如何通过选项卡上的无限滚动实现,这是我的html标记:

<ion-view title="All Wallpapers">
  <ion-content ng-controller="MyCtrl">
    <div class="row" >
    <div ng-controller="PostsController" >
        <div ng-repeat="post in posts">
            <div class="col col-50">
                    <div class="list card">
                          <div class="item item-image">
                            <img ng-src="{{post.thumbnail}}"></>
                          </div>
                          <a class="item item-icon-left assertive" href="#">
                            <i class="icon ion-android-image"></i>
                            {{post.thumbnail_images.full.width}} x {{post.thumbnail_images.full.height}}
                          </a>
                    </div>
            </div>
    </div>
  </div>
  </div>
     <ion-infinite-scroll ng-if="!noMoreItemsAvailable" on-infinite="loadMore()" distance="1%"></ion-infinite-scroll>
 </ion-content>
</ion-view>
Run Code Online (Sandbox Code Playgroud)

在我的apps.js我有:

wallweight.controller('PostsController', function($scope, $http) {
    $scope.page = 1;

    var url='http://wallweight.com/api/get_recent_posts?page';
    $http.get(url).
    success(function(data, status, headers, config) {

        $scope.posts = data.posts;
        console.log(data);
    }
).


    error(function(data, status, headers, config) {

    });


});
function MyCtrl($scope, $http) {
  $scope.posts = [];
  $scope.loadMore = function() {
    $http.get('http://wallweight.com/api/get_recent_posts?page=2').success(function(items) {
      $scope.posts.push($scope.posts.items);
      $scope.$broadcast('scroll.infiniteScrollComplete');
    });
  };

  $scope.$on('$stateChangeSuccess', function() {
    $scope.loadMore();
  });
}
Run Code Online (Sandbox Code Playgroud)

第二个函数会加载数据,但不会将其附加到原始数据.感谢您的时间.

PS,我已经看到了许多代码集示例,但是,我似乎无法让它们工作..

编辑:

好吧,香港专业教育学院设法缩小了问题.我现在误用控制器获取数据,但新数据取代旧数据,

  function MyController($scope, $http) {
  $scope.posts = [];
  $scope.page=1;
  $scope.loadMore = function() {
    $http.get('http://wallweight.com/api/get_recent_posts?page='+$scope.page).success(function(items) {
      $scope.posts=items.posts;
      console.log(items.posts);
      $scope.$broadcast('scroll.infiniteScrollComplete');
      console.log($scope.page);
      $scope.page +=1;
    });
  };
Run Code Online (Sandbox Code Playgroud)

我理解$ scope.posts = items.posts是错误的,我只是无法找到一种方法来追加它

Far*_*war 5

搞定了:)

function MyController($scope, $http) {
  $scope.posts = [];
  $scope.page=1;
  $scope.loadMore = function() {
    $http.get('http://wallweight.com/api/get_recent_posts?page='+$scope.page).success(function(items) {
     var i = items.posts.length;
     $scope.posts = $scope.posts.concat(items.posts);
     $scope.posts.push(items);
      console.log(items.posts[0]);
      $scope.$broadcast('scroll.infiniteScrollComplete');
      console.log($scope.page);
      $scope.page +=1;
    });
  };
Run Code Online (Sandbox Code Playgroud)