Вопрос

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?

Это было полезно?

Решение

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();
    },
    // ... 

});

Другие советы

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();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top