Reputation: 7959
I'm trying to wrap my head around Ember.js. I'm just writing a simple app that will need to load some data from local storage. When would I do this? Am I supposed to do this within the Route
's setupController
method? Or, am I supposed to do this in the Controller
?
Upvotes: 0
Views: 69
Reputation: 18672
You can create Ember.Object that is handler for saving/reading from local storage(has function read(), save(), some properties etc.) and use it as model in Ember.Controller. Then, you might have actions in this controller that call Model's functions, eg. using:
this.get('model').getLatestData();
Or instead of actions you can use computed properties like this:
directory: function() {
downloadPath = this.get('model.keys').filterBy('Name', 'downloadPath')[0];
if(downloadPath.Value != '' && downloadPath.Value !== undefined)
this.get('model').setValue('downloadPath', downloadPath.Value, db);
this.get('model').getLatestData(db);
return downloadPath.Value;
}.property('[email protected]')
You can see more code here on GitHub. I'm using Web Storage, but local storage is simplier.
Upvotes: 1