在原有项目中开发模块 Ionic v1.2.4 , AngularJS v1.3.13css
注意版本问题,angular即便都是版本1也存在api使用的不一样html
下拉刷新
<ion-refresher pulling-text="下拉刷新..." on-refresh="doRefresh()"></ion-refresher>
上拉加载<ion-infinite-scroll ng-if="historyListData.hasmore" on-infinite="loadMore()" immediate-check="false" distance="1%"></ion-infinite-scroll>
json
<ion-view> <ion-content> <ion-refresher pulling-text="下拉刷新..." on-refresh="doRefresh()"> </ion-refresher> <ion-list class="list c-tb-historybox"> <ion-item class="item c-tb-historyList" collection-repeat="item in historyListData.object" ng-click="godetail(item.troubleid)"> <!--<a ng-href="#/trouble/historyDetail/{{item.troubleid}}">--> <p class="row"><strong class="col col-85 c-title" ng-bind="item.troubletitle"></strong><span class="col c-time" ng-bind="item.reporttime| jsonDate:'MM-dd'"></span></p> <p class="row solve-box"> <span class="col col-25" ng-if="item.troublestatus===0">已登记</span> <span class="col col-25" ng-if="item.troublestatus===1">处理中</span> <span class="col col-25" ng-if="item.troublestatus===80">已解决</span> <span class="col col-25" ng-if="item.troublestatus===90">已关闭</span> <!--<span class="col c-solve">处理人: <b ng-if="item.dealperson" ng-bind="item.dealperson"></b> <b ng-if="!item.dealperson">暂未分配</b> </span>--> </p> <!--</a>--> </ion-item> </ion-list> <ion-infinite-scroll ng-if="historyListData.hasmore" on-infinite="loadMore()" immediate-check="false" distance="1%"> </ion-infinite-scroll> <div class="nomore" ng-if="!historyListData.hasmore">没有更多了</div> </ion-content> </ion-view>
//上拉刷新 $scope.doRefresh = function () { $scope.historyListData.pageIndex = 0; $scope.historyListData.hasmore = true; $http.get('/lapp/Trouble/GetMyTroubleList?pageIndex=' + $scope.historyListData.pageIndex + '&pageSize=' + $scope.historyListData.pageSize).success(function (response) { if (response.code === '1' && response.list.List.length > 0) { $scope.historyListData.object = response.list.List; $scope.historyListData.pageIndex++; if (response.list.List.length < $scope.historyListData.pageSize) { $scope.historyListData.hasmore = false; } } else { $scope.historyListData.hasmore = false; } $scope.$broadcast('scroll.refreshComplete'); }).error(function (response) { $scope.alert('网络不给力,请检查网络设置'); self.location = "vipoa://close"; }); }; //下拉加载 $scope.loadMore = function () { $http.get('/lapp/Trouble/GetMyTroubleList?pageIndex=' + $scope.historyListData.pageIndex + '&pageSize=' + $scope.historyListData.pageSize).success(function (response) { if (response.code === '1' && response.list.List.length > 0) { $scope.historyListData.object = $scope.historyListData.object.concat(response.list.List); $scope.historyListData.pageIndex++; if (response.list.List.length < $scope.historyListData.pageSize) { $scope.historyListData.hasmore = false; } } else { $scope.historyListData.hasmore = false; } $scope.$broadcast('scroll.infiniteScrollComplete'); }).error(function (response) { $scope.alert('网络不给力,请检查网络设置'); self.location = "vipoa://close"; }); }; //首次加载数据 $scope.$on('$stateChangeSuccess', function () { $scope.loadMore(); });
使用 ion-refresher 和 ion-infinite-scroll的时候,出现了每次下拉刷新的时候,都会屡次触发上拉加载控件的事件api
解决办法:网络
若是ion-infinite-scroll 的 immediate-check 属性没有设置 ,那么改成immediate-check="false"app
若是ion-infinite-scroll 的 immediate-check 属性值为 false ,那么将list-item的ng-repeat循环改成collection-repeat,由于ng-repeat由于未知缘由在下拉的时候会触发ion-infinite-scroll的滚动条距离底部不足1%这个条件,而collection-repeat则不会spa
还有一个缘由就是在下拉刷新的代码里写了$scope.$broadcast('scroll.infiniteScrollComplete');
反过来在上拉加载里写了$scope.$broadcast('scroll.refreshComplete');也会引发上拉加载触发下拉刷新code
遇到一个a连接包住图片的跳转问题,点击连接图片激活了图片预览,安卓原生加了处理以后图片预览不跳出,可是事实上只是隐藏了效果,图片预览层仍是存在,因此须要将图片作为css背景处理。htm