Javascript 在木偶集合/复合视图中手动填充集合

Javascript 在木偶集合/复合视图中手动填充集合,javascript,backbone.js,marionette,Javascript,Backbone.js,Marionette,所以,我在木偶中处理这个问题-我有3个嵌套的CompositeView。视图中的每个集合都取决于它的父级id。因此,我只能在获取集合的父级模型后才能获取集合。我的问题是,声明CompositeView后如何填充集合。让我向您展示一些代码: Env.Comp2 = Marionette.CompositeView.extend({ ..., childView: Env.Comp3, initialize: function () { var _this =

所以,我在木偶中处理这个问题-我有3个嵌套的CompositeView。视图中的每个集合都取决于它的父级id。因此,我只能在获取集合的父级模型后才能获取集合。我的问题是,声明CompositeView后如何填充集合。让我向您展示一些代码:

Env.Comp2 = Marionette.CompositeView.extend({
    ...,
    childView: Env.Comp3,
    initialize: function () {
        var _this = this;
        $.when(getEntities('secondCollection')).done(function (collection) {
            _this.collection = collection;
            /**
             *  Here is a problem. Is there a better way to fill the
             *  collection from inside? Or is there a way to parse
             *  the collection from it's parent CompositeView?
             **/
        }).then(function () {
            _this.render();
        });
    }
});

Env.Comp = Marionette.CompositeView.extend({
    ...,
    childView: Env.Comp2
});

Env.Index = Marionette.LayoutView.extend({
    ...,
    regions: { reg1: '#id' }
    onShow: function () {
        var _this = this;
        $.when(getEntities('firstCollection')).done(function (collection) {
            _this.getRegion('reg1').show(new Env.Comp({
                collection: collection
            }));
        });
    }
});
我确实简化了我的代码,但基本上它包含了一个示例结构