Marionette.CompositeView
これらの2つの例(1)と(2)に基づいて、serializeDataとonRenderの違いを理解したいと思います 。
ドキュメントによると、テンプレートを適用する前に serializeData が render で呼び出され、テンプレートを適用した後に onRender が render で呼び出されます。
私の質問は次のとおりです
。1)例(1)が機能し、(2)が機能しないのはなぜですか?
2) コレクションをリセットすると、Marionette.CompositeView
再レンダリングされますか?
詳細については、コード内のコメントを参照してください。
(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?
}
});