我的集合视图无法正确呈现,而是抛出错误...
这是我的代码:
var ContactManager = new Marionette.Application();
ContactManager.addRegions({
content : "#main-region"
})
ContactManager.Contact = Backbone.Model.extend();
ContactManager.Collection = Backbone.Collection.extend({
model : ContactManager.Contact
})
ContactManager.ContactView = Marionette.ItemView.extend({
template: "#contact-list-item"
});
ContactManager.on("start", function () {
var contacts = new ContactManager.Collection([
{
firstName: "Bob",
lastName: "Brigham",
phoneNumber: "555-"
},
{
firstName: "Alice",
lastName: "Arten",
phoneNumber: "555-0184"
},
{
firstName: "Charlie",
lastName: "Campbell",
phoneNumber: "555-0129"
}
]);
ContactManager.content.show(Marionette.CollectionView.extend({ //nothing renders here
tagName: "ul",
childView : ContactManager.ContactView,
collection : contacts
}));
})
ContactManager.start();
templates
中的所有DOM
都在{{}}},我收到错误消息:
Uncaught TypeError: undefined is not a function
有人帮我吗?
答案 0 :(得分:3)
您只是遗漏了一件事,当您在内容区域调用show
时,您需要传递集合视图的实例。
当Marionette尝试将事件绑定到您未实例化的视图时,它会抛出错误。
ContactManager.ContactCollectionView = Marionette.CollectionView.extend({ //nothing renders here
tagName: "ul",
childView : ContactManager.ContactView,
collection : contacts
});
ContactManager.content.show(new ContactManager.ContactCollectionView());