這是我如何解決集成Marionette和backbone.paginator的問題。從某種意義上說,這是「直截了當的」,但作爲骨幹隊的新來者,它讓我煩惱了一段時間!我希望這對某人有用。
在compositeView上使用serializeData方法來呈現paginator的paginator_ui對象中的信息。
/* a view for presenting a backbone.paginator collection,
* and for presenting and handling its pagination UI element */
App.module('Views', function(Views, App, Backbone, Marionette, $, _) {
Views.PaginatedCollectionView = Backbone.Marionette.CompositeView.extend({
template: 'backbone/templates/paginated_collection_view',
itemView: App.Views.StructureView,
/* I'm not using a model, but you could if you
* wanted? You might even merge the two */
serializeData: function(){
if (this.model){
data = this.model.toJSON();
} else {
// we want to render the paginator_ui in our templates
data = this.collection.paginator_ui;
}
return data;
}
});
});