在离子中拉动刷新不会刷新我的列表

时间:2016-07-07 07:26:34

标签: ionic-framework hybrid-mobile-app

使用离子拉动刷新功能不会更新我的列表。调用函数,并在服务器中检索控制台数据,但不刷新我的列表。

这是我的看法:                                                                 

        <ion-list>
            <ion-item class="list card" ng-repeat="pickup in pickups">
                <div class="item">
                    <h2>{{pickup.title}}</h2>

                    <p>Request Date : {{pickup.added_date}}</p>

                    <p>Status :
                        <span class="positive" ng-if="pickup.status==0">On Queue</span>
                        <span class="energized" ng-if="pickup.status==1">On Process</span>
                        <span class="balanced" ng-if="pickup.status==2">On Collected</span>
                        <span class="assertive" ng-if="pickup.status==2">Cancelled</span>
                    </p>
                </div>

                <div class="item item-body">
                    <p>Contact : {{pickup.b_contact}}</p>

                    <p>Location : {{pickup.b_location}}</p>

                    <p>
                        <a class="button circular-btn icon ion-android-done button-energized" href="#"
                           ng-click="statusData(pickup.pickupid,pickup.user_id,1)"
                           ng-if="pickup.status==0"></a>
                        <a class="button circular-btn ion-android-done-all button-balanced" href="#"
                           ng-click="statusData(pickup.pickupid,pickup.user_id,2)"
                           ng-if="pickup.status==0|| pickup.status==1"></a>
                        <a class="button circular-btn icon ion-close-circled button-assertive" href="#"
                           ng-click="statusData(pickup.pickupid,pickup.user_id,3)"
                           ng-if="pickup.status==0|| pickup.status==1|| pickup.status==2"></a>
                    </p>
                </div>

            </ion-item>
        </ion-list>
    </ion-content>

我的控制器代码:

.controller('AppCtrl', function ($scope, Service, $ionicLoading, $ionicModal, $ionicPopup, $timeout, $state, $http, $stateParams) {

$scope.doRefresh = function () {
    Service.getpickup($state, $http).success(function (data) {
        $scope.pickups = data.pickup_request;
        console.log(data.pickup_request);
    })
        .finally(function () {
            $scope.$broadcast('scroll.refreshComplete');
        });
}
  });

请指导我。提前谢谢。

2 个答案:

答案 0 :(得分:0)

  • 您是否在html中使用过离子复习标签?我在你的代码中看不到它。如果没有,请使用此

    <ion-refresher pulling-text="Pull to refresh..." on-refresh="doRefresh()">
    
  • 此外,尝试手动将项目添加到列表中,然后查看是否有效。 (检查data.pickup_request是否也是一个数组)

    $scope.pickups.push.apply($scope.pickups, data.pickup_request);
    

答案 1 :(得分:0)

我找到了问题。我在pickupCtrl中有视图,但我在另一个控件中调用了scope函数。谢谢你的每一位导游。非常感谢。