我正在尝试使用backbone.js paginator plugin的requestPager
来引入分页。
问题:在设置扩展collection
的{{1}}后,我刷新了网页,并且javascript控制台引发了错误:
Backbone.Paginator.requestPager
我对骨干很新,不知道出了什么问题。是因为我使用了Uncaught TypeError: Object function (a){return new m(a)} has no method 'result' backbone.paginator.js:678
,它出现在下面错误的屏幕截图中?我还注意到没有fetch()
个请求被发送到后端。发生了什么,我该怎么解决这个问题?谢谢!
JS代码
GET
JS代码
// Collection
window.ListingCollection = Backbone.Paginator.requestPager.extend({
model: Listing,
paginator_core: {
type: 'GET',
dataType: 'jsonp',
url: 'api/listings'
},
paginator_ui: {
firstPage: 0,
currentPage: 0,
perPage: 10,
totalPages: 10
},
server_api: {
'$filter': '',
'$per_page': function() { return this.perPage; },
'$current_row': function() { return this.currentPage * this.perPage; },
'$order_by': 'listing_id'
},
parse: function(response){
this.totalPages = Math.floor(response.total_rows / this.perPage);
}
});
Javascript控制台中的错误屏幕截图
JS包含
// Router
var AppRouter = Backbone.Router.extend({
routes: {
'': 'listings',
'listings': 'listings'
},
listings: function() {
var self = this;
// Load initial search results
this.listingList = new ListingCollection();
this.listingList.fetch({
success: function() {
self.listingListView = new ListingListView({ model: self.listingList });
$('#listing_list table').append(self.listingListView.render().el);
}
});
this.listingFilterView = new ListingFilterView();
}
});
答案 0 :(得分:4)
您可能正在使用较旧版本的Underscore。我使用1.3.1并且它没有result()
方法。下载新的作品version 1.3.3 - 它有result()
。