Domanda

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'); 
        },
...
È stato utile?

Soluzione

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');
    }
});

Altri suggerimenti

There's always:

initialize: function(){
    var self = this;
    self.fetch({
        success: function(){
            self.trigger('fetched'); 
        },
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top