Question

Is there a way to ask Backbone.Model to fetch silently? the option {silent: true} does not work for model fetch. Basically I wanted to silent the sync event which is already listened by current view.

ListenTo:

self.listenTo(self.model, 'sync', self.subscriberParameterSyncSuccesfully);

Fetch :

self.model.fetch({
    success: function() {
        self.bindEventsToModel();
        self.renderDetailsBody(false);
    },
    error: self.handleRouteError
}, {silent: true});
Was it helpful?

Solution

No, you can't. Backbone always trigger "sync" event in a success response. What you can do though is to make a fetch wrapper and fires another event. so you avoid depending on the sync event.

self.listenTo(self.model, 'mysync', self.subscriberParameterSyncSuccesfully);

Model:

myfetch: function (option) {
    this.fetch.call(this, option);
    this.trigger('mysync', this);
}

self.model.myfetch(option);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top