Javascript 木偶组合视图
我有一个主干木偶复合视图如下 这是初始化方法Javascript 木偶组合视图,javascript,backbone.js,marionette,Javascript,Backbone.js,Marionette,我有一个主干木偶复合视图如下 这是初始化方法 initialize: function(options) { log.debug("Initialize"); this.wizard = options.wizard; this.model = new Feed({ id: options.modelid }); this.modelid = options.modelid;
initialize: function(options) {
log.debug("Initialize");
this.wizard = options.wizard;
this.model = new Feed({
id: options.modelid
});
this.modelid = options.modelid;
this.collection = new Similar();
this.listenTo(this.model, "change", this.onFetch);
this.listenTo(this.model, "reset", this.onFetch);
this.collection.fetch({ data: { id: this.modelid }});
this.model.fetch();
},
这是onFetch方法
onFetch: function() {
log.debug("Fetch");
this.$el.html(this.template(this.model.toJSON()));}
这是append方法
appendHtml: function(collectionView, itemView, index) {
log.debug("appendHtml");
var jsonFeed = itemView.model.toJSON();
if (this.prevFeed === null || jsonFeed.start !== this.prevFeed.start) {
var date = new Date(jsonFeed.start);
collectionView.$(this.itemViewContainer).append('<div class="day-divider c-color box-center" ><h3>' + moment(date).format('DD MMMM') + '</h3></div>');
}
collectionView.$(this.itemViewContainer).append(itemView.el);
this.prevFeed = jsonFeed;
},
知道这是怎么发生的吗?
如何解决问题?为什么不使用onFetch的onRender instad? onRender是一个已经包含的函数,在渲染完成时显示内容
注意:您甚至可以使用onShow,它在所有内容都已呈现的情况下执行此任务。经过思考,我得出结论,该方法是:$el.html(this.template(this.model.toJSON());}应该放在render方法中(覆盖主干方法)。
DEBUG - Initialize
DEBUG - Render
DEBUG - appendHtml
DEBUG - appendHtml
DEBUG - appendHtml
DEBUG - Render
DEBUG - Fetch