我是骨干和骨干布局经理的新手。我正在尝试呈现联系人列表。这是一段代码
var ContactListView = Backbone.Layout.extend({
tagName: 'li',
initialize: function (){
console.log('ContactListView init');
this.render();
},
render: function (){
console.log('Rendering all items in the contact list');
_(this.collection.models).each(function (contact){
var contactlistitem = new ContactListItemView({model: contact});
self.$el.append(contactlistitem.el);
});
}
});
var ContactListItemView = Backbone.Layout.extend({
initialize: function (){
this.render();
},
render: function (){
console.log('called');
var template = Handlebars.compile($('#contact-list-item').html());
this.el.html(template(this.model));
}
});
当我导航到该页面时,控制台会记录“ContactListView init”,但不会输出“正在渲染联系人列表中的所有项目”。为什么是这样?