samedi 14 janvier 2017

ember local storage adapter: how to get data and work on it

I use Ember in combination with Electron.

As the user can define some settings for the app, I thought it was a elegant idea to store the settings data in local storage.

For that I use ember-local-storage adapter.

Storing, deleting and displaying this data works like a charm BUT These settings should be used in some functions, so I want to get them out of the local storage. I expected an array or JSON object- or even the same format as it is shown in local storage. But I only receive a huge abstract object ?!

This is what I want to store (e.g.):

{"identifier":"identifier1","bid":"6653ggd245","name":"test1"}
{"identifier":"identifier2","bid":"kkhd7765vv","name":"test2"}

This is what is displayed in localstorage (dev tools):

{"buttons":
  {"records":
    {"i7lvj":{"id":"i7lvj","identifier":"identifier1","bid":"6653ggd245","name":"test1"},"i80vm":{"id":"i80vm","identifier":"identifier2","bid":"kkhd7765vv","name":"test2"}
  }}}

This is how I tried to access the data:

this.get('store').findAll('buttons').then(function(SavButtons){

      console.log(SavButtons);
 });// gett all stored buttons


this.get('store').findRecord('buttons','i7lvj').then(function(SavButtons){

      console.log(SavButtons.data);
 });// get specific button -> works 

This data is the base to generate an params array to use for Promises for API requests. What can I do to get this in a reusable structure ? For example: 0:{record1} 1:{record2}

Or is there even a simpler/better way to store settings made by the user after the app is closed, maybe I am missing something.

Thanks a lot!




Aucun commentaire:

Enregistrer un commentaire