下面是我如何解决集成 Marionette 和backbone.paginator 的问题。从某种意义上说,这是“直截了当”的,但作为一个新来的骨干。牵线木偶它让我烦恼了一段时间!我希望这对某人有用。
使用复合视图上的 serializeData 方法从分页器的 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;
}
});
});