2017-03-06 5 views
0

私は現在、symfony 1.4のレガシープログラムと時代遅れの技術を取り組んでいます。最近では、バックボーン/マリオネットをプロジェクトに追加することで、物事をもっと簡単にすることに決めました。Marionette 3 CollectionViewをテーブルの列にレンダリングするには?

私が直面してる問題はテーブル列コレクションビューをレンダリングです。テーブルがすでに存在し、その背後に2k LOC以上ので機能しているため、ATMに書き換えることができません。

<table> 
<thead> 
<tr> 
    <th>Item</th> 
    <th>Quantity</th> 
    <th>Price</th> 
    <th>...</th> 
    <th></th> <!-- This is the column --> 
    <th>Total price</th> 
</tr> 
</thead> 
<tbody> 
    ... 
</tbody> 
</table> 

コメントで指定された以外のすべての列は、既にページにレンダリングされています。私はMarionette attachHtmlattachBufferに文書をたどりましたが、実際の解決策を実装できませんでした。

答えて

1

https://jsfiddle.net/cbzs67ar/

var collection = new Backbone.Collection([ 
    { id: 1, text: 'one' }, 
    { id: 2, text: 'two' }, 
    { id: 3, text: 'three' }, 
    { id: 4, text: 'four' }, 
    { id: 5, text: 'five' }, 
    { id: 6, text: 'six' }, 
    { id: 7, text: 'seven' } 
]) 

var MyChildView = Mn.View.extend({ 
    initialize() { 
    this.render(); 
    }, 
    template: _.template(': <%- text %>') 
}); 
var CollectionView = Mn.CollectionView.extend({ 
    el: '.tbody-hook', 
    childView: MyChildView, 
    buildChildView(model, ChildView) { 
    var view = new ChildView({ 
     el: '.td-' + model.id, 
     model: model 
    }); 
    return view; 
    }, 
    attachHtml: _.noop, 
    attachBuffer: _.noop 
}); 

var myRegion = new Marionette.Region({ el: '#some-region' }); 

myRegion.show(new CollectionView({ collection: collection })); 

カラムセレクタによってプリレンダリングされた子を管理するcollectionviewを使用。コレクションビューを無効にして、子を独自のコンテナにアタッチしないようにする必要があります。インスタンス化された後に子を強制的にレンダリングする必要があります。

関連する問題