0

https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.view.md

この例では:

<script id="my-template" type="text/html">
  I think that <%= showMessage() %>
</script> 

MyView = Backbone.Marionette.ItemView.extend({
  template: "#my-template",

  templateHelpers: {
    showMessage: function(){
      return this.name + " is the coolest!"
    }
  }

});

model = new Backbone.Model({name: "Backbone.Marionette"});
view = new MyView();
view.render(); //=> "I think that Backbone.Marionette is the coolest!";

このコードを分析してみましたが、Backboneの理解に基づいて、ビューが関連付けられているモデルを指定する必要があります。マリオネットビューを理解しようとしましたが、ドキュメントのどの部分か、この例ではthis、新しく作成されたモデルを参照するビューがどのように認識されているかがわかりません。それともこれは単なるタイプミスですか?

4

1 に答える 1

1

その例にはエラーがあります。これを表示する必要があります:


model = new Backbone.Model({name: "Backbone.Marionette"});

view = new MyView({
  model: model
});

view.render(); //=> "I think that Backbone.Marionette is the coolest!";

これを修正するためにドキュメントを更新します

于 2012-06-25T12:45:58.617 に答える