本文介绍了Backbone.Marionette CollectionView回调何时所有itemViews都已完成渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用牵线木偶Layout
.show
渲染CollectionView
,并且想知道是否有一种方法可以检测所有子级ItemView
子项何时完成渲染? /p>
我的代码的简化版本是:
布局
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
一起使用?
解决方案
您可以侦听"render"事件,或在视图上提供"onRender"回调函数.
MyView = Marionette.CollectionView.extend({
onRender: function(){
// the list of items has been rendered. do stuff here
}
});
var view = new MyView();
view.on("render", function(){
// the list of items has been rendered. do stuff here
});
I'm using the marionette Layout
.show
to render a CollectionView
and was wondering if there is a way of detecting when all the ItemView
children have finished rendering?
A simplified version of my code is:
Layout
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());
I noticed in the docs that there is mention of a .done
function:
new MyCollectionView().render().done(function(){
// all of the children are now rendered. do stuff here.
});
Is it possible to use this with the Layout
?
解决方案
You can listen to a "render" event, or provide an "onRender" callback function on the view.
MyView = Marionette.CollectionView.extend({
onRender: function(){
// the list of items has been rendered. do stuff here
}
});
var view = new MyView();
view.on("render", function(){
// the list of items has been rendered. do stuff here
});
这篇关于Backbone.Marionette CollectionView回调何时所有itemViews都已完成渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!