Reputation: 1349
I am using backbone model in my application but the problem is that I want to perform some function after id is assigned to newly created Model. I am using this
activeWidget.on('sync', this.addToCollectionWidget(activeWidget));
But this.addToCollectionWidget method is called before id is assigned to the model. Please help.
Upvotes: 0
Views: 101
Reputation: 4340
You should call the function in a callback. Your current code will work if addToCollectionWidget
return a function.
This should work:
activeWidget.on('sync', function() {
this.addToCollectionWidget(activeWidget); //you should careful with `this` in the callback context.
});
Upvotes: 1