这些函数 (*) 和 (**) 位于 < code> backbone.View 内, 但我认为不需要 Backbone 的知识来解决这个问题 。
As you can see from my comments in the code when:
1) I call the getAvatar
function everything is ok,
2) when the getAvatar call the setAvatar
something is broken
我应如何解决以下问题?
(*)
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 );
}