-
Notifications
You must be signed in to change notification settings - Fork 108
Local fetch() has no complete() callback. #27
Comments
Neither this variant seems to be working: var Favourites = Backbone.Model.extend({
local: true, //Only sync against LocalStorage
url: 'favourites',
initialize: function(){
var self = this;
this.fetch({
success: function(){
console.debug(self);
}
});
},
}); |
I would expect the second to work. If it doesn't, that's a bug. |
Since for localstorage there's no XMLHttpRequest to pass back, you're not going to be able to hook in I'm surprised that your second example didn't work. I have several tests in my fork that test both the local: true option and the success callback. This spec relies on the fetch success callback for the test to pass. I tried it with local: true on the model instead of remote: false in the fetch call, which also worked. I also rely on this fetch success callback in one of my apps that uses this plugin. |
I put together a jsfiddle with your code, and it seems to work. Run this, and you see the debug output in the console: |
Yeah that seems to work. Odd thing that I couldn't get it working in my code then. I'll close this off then. |
If you have jquery, you can wrap the dfdFetch: =>
$.Deferred((deferred) => @fetch
success: deferred.resolve
error: deferred.reject).promise() And then you can do things like |
With the fallowing example-code with the local attribute set to true:
this.fetch().complete() is not defined. This deferred call is a function from the jQuery ajax() function. This usage was recommended to me in this Backbone bug: jashkenas/backbone#423
The text was updated successfully, but these errors were encountered: