我正在读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。我究竟做错了什么?

最佳答案

似乎您需要先创建模型再创建实例

ContactManager.ContactView = Marionette.ItemView.extend({
    template: "#contact-template"
});

ContactManager.Contact = Backbone.Model.extend({});

关于javascript - Marionette :未被捕获的TypeError:*不是构造函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41613462/

10-11 11:48