3

私は次のCompositeView(1)を持っています。
MyCollectionの各モデルについて、そのようなものを作成するために2つのテンプレートとビューをレンダリングするための最良の方法は何でしょうか(2)。


(1)

var MyCompositeView = Marionette.CompositeView.extend({

    template: myTemplate,

    itemView: myView,

    collection: new MyCollection(),

    initialize: function () {
        this.collection.fetch();
    },

    appendHtml: function (collectionView, itemView) {
        collectionView.$el.find('ul').append(itemView.el);
    }

});

(2)

    appendHtml: function (collectionView, itemView1, itemView2) {
        collectionView.$el.find('ul').append(itemView1.el);
        itemView.$el.append(itemView2.el);
    }
4

1 に答える 1

2

目標を達成する別の方法は、結果は同じである必要があり、次のように定義することonRender funcitonですMarionette.ItemView

のコードは次のMarionette.ItemViewようになります。

    onRender: function () {
        var itemView2 = new ItemView2();

        itemView2.render();
        this.$el.append(itemView2.$el);
    }
于 2012-07-23T12:25:19.010 に答える