سؤال

I have a collection of models in Backbone. One model is triggering a custom event, that I can catch, listening to the collection. What is the best way to find out, which model triggered the event?

هل كانت مفيدة؟

المحلول

You can add the model ID with your custom event like this:

yourModel.trigger('customEvent', yourModel.get('id'))

and on the callback that catch the custom event you'll get the id as a parameter:

yourCallback: function(id) {
    ...
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top