简体   繁体   中英

Marionette: Uncaught TypeError: * is not a constructor

I am reading Marionette gentle introduction book. I am following Displaying a Model chapter and have following code:

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();

and following element in html page:

<script type="text/template" id="contact-template">
    <p><%- firstName %> <%- lastName %></p>
</script>

I receive error: Uncaught TypeError: ContactManager.Contact is not a constructor . What am I doing wrong?

Seems you need to declare your model first before crating it's instance

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM