所有itemViews完成渲染后Backbone.Marionette CollectionView回调?

时间:2012-11-23 12:41:45

标签: marionette

我正在使用牵线木偶Layout .show来渲染CollectionView,并想知道是否有办法检测何时所有 {{1}孩子们已经完成了渲染?

我的代码的简化版本是:

布局

ItemView

的CollectionView

Layouts.Group = Backbone.Marionette.Layout.extend({

    template: Templates.group,

    ...

    regions: {
        header: ".group-header"
        details: ".group-details"
    },

    ...

});

ItemView控件

Views.GroupDetail = Backbone.Marionette.CollectionView.extend({

    itemView: groupDetailRow,

    ...

    onRender: function () {

        // do something here after rendering *all* groupDetailRows of information for group detail section

    }

});

.show

Views.GroupDetailRow = Backbone.Marionette.ItemView.extend({

    onRender: function () {

        // single groupDetailRow of information

    }

});

我在文档中注意到提到了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. });

一起使用

1 个答案:

答案 0 :(得分:2)

您可以收听“渲染”事件,或在视图上提供“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
});

https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.collectionview.md#render--onrender-event