I currently have a working backbone.js requestPager collection, but would like to use the filter option. I am currently struggling with how to make it work. It works when I just use something link "'filter': 'sam'" in the server_api function, but I can't seem to get this work dynamically.
I think where I'm running into issues is with how to setup the view to update the collection. With clientPager there is a this.collection.setFilter() function, but there doesn't seem to be an equivalent for requestPager.
Can anyone point me to simple example of result filtering with the requestPager?
I did this similar to user1248256, and thought I'd post as well.
Here's the relevant code from the collection:
server_api: {
'filter': function() {return this.filterString },
'limit': function() { return this.perPage },
'offset': function() { return this.currentPage},
},
setFilter: function (filter) {
this.filterString = filter;
this.pager();
}
It depends on your app design. At a simple case, you could write something like this:
var PaginatedCollection = Backbone.Paginator.requestPager.extend({
setFilter: function (filter) {
this.server_api['$filter'] = filter;
this.currentPage = 0;
this.fetch();
},
// ...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.