ali asad
ali asad

Reputation: 1349

How to trigger an event only after id is assigned to backbone model after save() method

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

Answers (1)

BMH
BMH

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

Related Questions