6
我使用的木偶Layout
.show
渲染CollectionView
,並想知道是否有當所有的ItemView
孩子們呈現完畢檢測的方法嗎?Backbone.Marionette CollectionView回調,當所有的itemViews已經完成渲染?
我的代碼的簡化版本如下:
佈局
Layouts.Group = Backbone.Marionette.Layout.extend({
template: Templates.group,
...
regions: {
header: ".group-header"
details: ".group-details"
},
...
});
的CollectionView
Views.GroupDetail = Backbone.Marionette.CollectionView.extend({
itemView: groupDetailRow,
...
onRender: function() {
// do something here after rendering *all* groupDetailRows of information for group detail section
}
});
ItemView控件
Views.GroupDetailRow = Backbone.Marionette.ItemView.extend({
onRender: function() {
// single groupDetailRow of information
}
});
.show
var details = new Views.GroupDetail();
details.show(new DV.Time.Views.GroupDetail());
我注意到在文檔中,有一個.done
功能的提及:
new MyCollectionView().render().done(function(){
// all of the children are now rendered. do stuff here.
});
是否有可能與Layout
使用?
謝謝! 如果CollectionView通過AJAX請求數據,佈局的onRender函數是否會等待,直到它在運行之前返回? – jlund
no - onRender在「渲染」功能完成後被調用。渲染函數真的不在乎視圖中是否有任何項目,就其何時觸發該方法/事件而言。您需要聽取該集合的「重置」事件以瞭解它何時完成抓取。 –
兩種解決方案('onRender'和'reset')都不起作用。 - 我不得不聽收集'同步'事件。 (奇怪的是)當觸發該事件時,假設「CollectionView」的所有項都完全呈現,這顯然是安全的。 –