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
引用了新创建的模型。或者这只是一个错字?
答案 0 :(得分:1)
该示例中存在错误。它应该表明:
model = new Backbone.Model({name: "Backbone.Marionette"});
view = new MyView({
model: model
});
view.render(); //=> "I think that Backbone.Marionette is the coolest!";
我会更新文档以解决此问题