Question

Is there a way how to refer to owner-collection from the success-event. example, i am using this where i want to refer to the collection:

var col = Backbone.Collection.extend({
model: MobileService,
url: 'file.json',

initialize: function(){
    this.fetch({
        success: function(){
            this.trigger('fetched'); 
        },
...
Was it helpful?

Solution

From the fine manual:

fetch collection.fetch([options])

[...] The options hash takes success and error callbacks which will both be passed (collection, response, options) as arguments.

So you can use:

this.fetch({
    success: function(collection) {
        collection.trigger('fetched');
    }
});

OTHER TIPS

There's always:

initialize: function(){
    var self = this;
    self.fetch({
        success: function(){
            self.trigger('fetched'); 
        },
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top