6

我正在使用木偶Layout .show来渲染 aCollectionView并且想知道是否有一种方法可以检测所有孩子何时完成渲染ItemView

我的代码的简化版本是:

布局

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

    template: Templates.group,

    ...

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

    ...

});

集合视图

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

    itemView: groupDetailRow,

    ...

    onRender: function () {

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

    }

});

项目视图

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.
});

是否可以将其与 一起使用Layout

4

1 回答 1

2

你可以监听一个“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
});

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

于 2012-11-23T13:23:48.863 回答