backbone.paginator
ページ化されたコレクション(プラグイン)を複数のビューに渡して共有し、同じコレクションを使用して3つのビューの関数を呼び出せるようにしようとしています。
ただし、他のビュー(およびページごとAttendeesView
)を呼び出している私のメインビュー()。ビューのコンストラクター、ルーターによってそれを渡そうとしました。私はそれを機能させることができないように思われるので、私はそれに取り組むことができるようにアイデアが必要になるでしょう。PaginationBarView
AttendeeView
編集:ちなみに、Uncaught TypeError: Cannot call method 'on' of undefined
コレクションにイベントを追加しようとすると、PaginatedBarでエラーが発生します。見つかりません。
AttendeesCollection
(ページ付け)
define([
'jQuery',
'Underscore',
'Backbone',
'models/AttendeeModel',
'libs/plugins/backbone.paginator'
],function($, _, Backbone, Attendee,Paginator){
var AttendeesCollection = Paginator.requestPager.extend({
model: Attendee,
... (Works)
return AttendeesCollection;
});
define([
'jQuery',
'Underscore',
'Backbone',
'libs/plugins/bootstrap-dropdown',
'text!templates/PaginationBar.phtml'
],function($, _, Backbone, twdd, PaginationBarTPL){
var PaginationBar = Backbone.View.extend({
events: {
'click a.PBNext': 'nextResultPage',
'click a.PBPrev': 'previousResultPage',
'click a.PBSort': 'updateSortBy',
'click a.PBPage': 'gotoPage'
},
initialize: function(){
_.bindAll(this,'render','updateSortBy','nextResultPage', 'previousResultPage', 'gotoPage');
this.collection.on('reset', this.render, this);
this.collection.on('change', this.render, this);
}
(...)
});
return PaginationBar;
});
define([
'jQuery',
'Underscore',
'Backbone',
'facade',
'views/PaginationBarView',
'text!templates/attendees.phtml',
'collections/AttendeesCollection'
],function($, _, Backbone,facade,PaginationBarView,AttendeesTPL,AttendeesCollection){
var AttendeesView = Backbone.View.extend({
el: "#attendees",
collection: new AttendeesCollection,
paginationbar: new PaginationBarView({collection: this.collection}),
initialize: function(){
_.bindAll(this, 'render', 'onClose');
$(this.el).find(".paginationBar").append(this.paginationbar.render().el)
this.collection.on('change', this.addAll, this);
this.collection.on('reset', this.addAll, this);
this.collection.on('add', this.addOne, this);
this.collection.pager();
},
(...)
});
return AttendeesView;
});