【发布时间】:2018-01-28 16:05:15
【问题描述】:
我正在使用 Ionic Framework 开发产品目录应用程序,并使用 php 从 database 和 ajax 在前端加载它,一切都很好,但是当我尝试按类别过滤时,response 返回一个json,里面有超过 1xxx 个项目,这会损害 用户体验强>。
代码->
控制器->
$scope.$on('$stateChangeSuccess', function() {
$scope.loadMore(); //Added Infine Scroll
});
// Loadmore() called inorder to load the list
$scope.loadMore = function() {
str=sharedFilterService.getUrl();
$http.get(str).success(function (response){
window.localStorage.setItem( 'app-name', JSON.stringify(response));
var appData = JSON.parse( window.localStorage.getItem( 'app-name' ));
$scope.menu_items = appData;
$scope.hasmore=response.has_more; //"has_more": 0 or number of items left
$scope.$broadcast('scroll.infiniteScrollComplete');
});
};
服务->
.factory('sharedFilterService', [function(){
var obj = {};
obj.str = "http://pathtoscript.php";
obj.getUrl=function(){
obj.str="http://pathtoscript.php"; // pass the value to url
console.log("URL",obj.str);
return obj.str;
};
return obj;
}])
离子 html
<ion-list ng-repeat="item in menu_items">
<ion-item class="item-thumbnail-left" >
<ion-slide-box auto-play ="true" does-continue="true" show-pager="false" >
<ion-slide ng-repeat="image in item.image">
<img ng-src="{{image.url}}" ng-click="showProductInfo(item.p_id,item.p_description,image.url,item.p_name,item.p_price)" >
</ion-slide >
</ion-slide-box>
<p style="position:absolute;right:10px;">
<a ng-click="addToCart(item.p_id,item.p_image_id,item.p_name,item.p_price)" class="button button-balanced button-clear icon ion-android-cart"> </a>
</p>
<h2 ng-click="showProductInfo(item.p_id,item.p_description,item.p_image_id,item.p_name,item.p_price)" > {{item.p_name}} </h2>
<p ng-click="showProductInfo(item.p_id,item.p_description,item.p_image_id,item.p_name,item.p_price)">Price: {{item.p_price}}</p>
</ion-item>
</ion-list>
我的问题是我可以从 php 脚本中仅加载一些项目,并在需要时从最后一个位置继续。
【问题讨论】:
-
做后端分页或者懒加载器
标签: php angularjs json ionic-framework angularjs-http