I am using Backbonejs to build an app for a vehicle head unit. I wish to persist some of my models using the framework's read/write functions rather than using HTTP requests.
Looking at the documentation for the fetch method at backbonejs.org, not much is explained. I'm assuming that I will simply need to override the save() and fetch() methods.
This is working fine for save as follows:
save: function () {
var json = this.toJSON();
console.log('Saving model state: ' + JSON.stringify(json));
sdk.save_json_file('my_model.json', json);
}
For fetch, I'm not exactly sure what this should look like. I've tried:
fetch: function () {
var json = sdk.read_json_file('my_model.json');
return json;
}
Can someone show me how to correctly do this?