这些函数 ( * ) 和 ( ** ) 在 aBackbone.View
中,但我认为不需要 Backbone 的知识来解决这个问题。
正如您从我在代码中的注释中看到的那样:
1)我调用该getAvatar
函数一切正常,
2)当 getAvatar 调用时,setAvatar
某些东西被破坏了
我应该如何解决以下问题?
( * )
getAvatar: function ()
{
var creatorIds = this.getCreatorIds();
console.log(creatorIds); // [1,2] ****** here is ok *******
for (var c = 0, l = creatorIds.length; c < l; c += 1) {
if (typeof this.avatars[creatorIds[c]] === 'undefined') {
this.userModel = new UserModel({id: creatorIds[c]});
this.userModel.fetch();
this.userModel.on('change', this.setAvatar, this);
}
}
},
( ** )
setAvatar: function ()
{
console.log(this.userModel.get('id')); // 2, 2 ********* it should be 1, 2 *******
this.names[this.userModel.get('id')] = this.userModel.get('name');
this.avatars[this.userModel.get('id')] = typeof this.userModel.get('avatar');
this.render();
},
( * )
initialize: function ()
{
_.bindAll(this, 'getAvatar', 'setAvatar');
}