Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fake model response in backbone.js

How can I fake a REST response in my model s.t. it does not really go to the service but returns a fixed json?

If possible show me a version that does it with overriding sync() and a version that overrides fetch(). I failed with both so this will be a good education for as for the difference between them.

like image 273
Yaron Naveh Avatar asked Jun 25 '12 16:06

Yaron Naveh


1 Answers

Backbone.Model.extend({
  fetch: function(){
    var model = this;
    model.set({yourStatic: "Json Here"});
  }
}

This should work. From the Backbone documentation:

fetch(): Resets the model's state from the server by delegating to Backbone.sync

like image 161
skyw00lker Avatar answered Nov 15 '22 06:11

skyw00lker