【发布时间】:2016-11-21 11:01:54
【问题描述】:
我有一个 Backbone 应用程序,我通过单击列表中的字母来获取不同的集合。所以,我想添加一个进度条或某种旋转图像,但我不知道该怎么做。
我的视图是这样的
function (App, Backbone) {
var Artists = App.module();
var ArtistView = Backbone.View.extend({
tagName : 'li',
template: 'artistItem',
serialize: function() {
var data = this.model.toJSON();
data.letter = this.model.collection.letter;
return data;
},
});
Artists.View = Backbone.View.extend({
tagName : 'ul',
className : 'artistList',
initialize: function() {
this.listenTo(this.collection, 'all', this.render);
this.listenTo(App, 'navigateLetter', this.updateState);
},
beforeRender: function() {
var self = this;
this.collection.each(function(item) {
self.insertView(new ArtistView({model: item}))
})
},
updateState: function(letter) {
this.collection.letter = letter;
this.stopListening(this.collection);
this.collection.fetch();
this.listenTo(this.collection, 'all', this.render);
}
});
Artists.ArtistsCollection = Backbone.Collection.extend({
url: function() {
return '/projects/mdk/index.php/api/artists/' + this.letter;
}
});
return Artists;
});
那么有人知道如何做到这一点吗?我可以想象我应该在 initialize 或 beforeRender 中做点什么?
提前致谢
【问题讨论】:
标签: backbone.js