【发布时间】:2012-08-09 22:42:47
【问题描述】:
我正在使用Marionette.CompositeView,我想了解serializeData 和onRender 之间的区别
基于这两个示例(1)和(2)。
根据文档serializeData在应用模板之前在render中调用,onRender在应用模板之后在render中调用。
我的问题是:
1) 为什么示例 (1) 有效而 (2) 无效?
2) 如果我重置集合,Marionette.CompositeView 会重新渲染吗?
请查看代码中的 cmets 了解更多详情。
(1)
return Marionette.CompositeView.extend({
initialize: function () {
this.collection = new MyCollection();
this.collection.fetch();
},
onRender: function () {
this.collection.length > 0 ? this.$el.show() : this.$el.hide();
// it returns this.collection.length > 0
// differently from serializeData.
}
});
(2)
return Marionette.CompositeView.extend({
initialize: function () {
this.collection = new MyCollection();
this.collection.fetch();
},
serializeData: function () {
this.collection.length > 0 ? this.$el.show() : this.$el.hide();
// it returns this.collection.length = 0
// even if this.collection.length > 0. Why?
}
});
【问题讨论】:
标签: javascript backbone.js marionette