骨干牵线木偶的视图如何知道哪种模型与之相关?

时间:2012-06-25 01:17:45

标签: marionette

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引用了新创建的模型。或者这只是一个错字?

1 个答案:

答案 0 :(得分:1)

该示例中存在错误。它应该表明:


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

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

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

我会更新文档以解决此问题