我正在阅读Marionette gentle introduction本书。我正在关注显示模型章节并拥有以下代码:
ContactManager.ContactView = Marionette.ItemView.extend({
template: "#contact-template"
});
ContactManager.on("start", function(){
var alice = new ContactManager.Contact({
firstName: "Alice",
lastName: "Arten",
phoneNumber: "555-0184"
});
var aliceView = new ContactManager.ContactView({
model: alice
});
ContactManager.regions.main.show(aliceView);
});
ContactManager.start();
以及html页面中的以下元素:
<script type="text/template" id="contact-template">
<p><%- firstName %> <%- lastName %></p>
</script>
我收到错误:Uncaught TypeError: ContactManager.Contact is not a constructor
。我究竟做错了什么?
答案 0 :(得分:2)
似乎你需要在装箱之前先申报你的模型
ContactManager.ContactView = Marionette.ItemView.extend({
template: "#contact-template"
});
ContactManager.Contact = Backbone.Model.extend({});