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 的理解,您必须指定视图与哪个模型相关联。我尝试理解 Marionette 视图,但我不知道文档的哪一部分或在此示例中显示视图如何知道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 回答