由于某种原因,我无法在此视图中触发 addOne 方法。渲染方法触发得很好。集合是从另一个实例化它的模块传入的。当我将括号添加到方法调用时,它会触发,但下划线会引发错误。
define(['backbone',
'jquery',
'underscore',
'views/user',
'models/user',
],
function(Backbone,$,_,UserView,UserModel){
var Users= Backbone.View.extend({
tagName:'ul',
className:'well',
initialize:function() {
_.bindAll(this);
},
render:function() {
this.collection.each( this.addOne, this );
return this;
},
addOne:function() {
console.log('inside of addOne');
var userView = new UserView({model:UserModel});
this.$el.append(userView.render().el);
}
});
return Users;
});