Boe*_*edy 8 backbone.js marionette
我一直在使用木偶一周,它真的让我的生活更轻松!
现在我需要能够在提取集合或模型时通知用户,因为某些视图需要花费大量时间来呈现/获取.举个例子,我做了一个小模型:

当用户单击某个类别时,需要加载该类别中所有项目的集合.在获取集合之前,我想显示加载视图,如图所示(视图1).实现这一目标的优雅解决方案是什么.我找到了以下帖子,其中用户启用了获取触发器:http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress.这似乎有效,但并不像我想的那样.这是我提出的:
var ItemThumbCollectionView = Backbone.Marionette.CollectionView.extend({
collection: new ItemsCollection(userId),
itemView: ItemThumbView,
initialize: function(){
this.collection.on("fetch", function() {
//show loading view
}, this);
this.collection.on("reset", function() {
//show final view
}, this);
this.collection.fetch();
Backbone.history.navigate('user/'+identifier);
this.bindTo(this.collection, "reset", this.render, this)
}
});
Run Code Online (Sandbox Code Playgroud)
如果我可以有一个名为'LoadItemView'的可选属性,那就太好了.这将在获取期间覆盖itemView.在您看来这是一个很好的做法吗?
几天前,Derick Bailey 在 Marionette Wiki 中发布了一个可能的解决方案:https://github.com/marionettejs/backbone.marionette/wiki/Displaying-A-%22loading-...%22-Message-For-A -集合或复合视图
| 归档时间: |
|
| 查看次数: |
8651 次 |
| 最近记录: |