私は1つのビューで2つのモデルを使用しようとしています。私はマリオネットと一緒に働いています。ここで私は、ビューの初期設定である:テンプレート2つのモデルを1つのビューで表示 - バックボーン/マリオネット
APP.Views.HeaderView = Backbone.Marionette.ItemView.extend({
template : '#view_template',
className: 'container',
initialize: function() {
//This correctly logs the second model
console.log(this.options.model2);
}
});
そして、ここではテンプレートです:
<script id="view_template" type="text/template">
<p>{{twoModel_label}} {{oneModel_data}}</p>
<p>{{twoModel_label2}} {{oneModel_data2}}</p>
</script>
それはoneModelデータを使用して、すべてを正しくレンダリングしますが、ここで
main_app_layout.header.show(new APP.Views.HeaderView({
model: oneModel,
model2 : twoModel}
));
は、私の見解でありますそれを正しく記録しても、2番目をレンダリングしません。私はテンプレート言語としてMustacheを使用しています。
誰でも手助けできますか?
これは素晴らしいです - デリックにお返事いただきありがとうございます! (私はマリネッテが大好きです!)。しかし、私はmodel2が未定義であるというエラーが発生し続けています(特に、未定義のメソッド 'toJSON'を呼び出せません)。 – streetlight
model2をthis.options.model2に変更してこの問題を修正しました!再度、感謝します! – streetlight
おっと! right ... this.options.model2 :) –