Page 1 of 1

Save array to local storage or database and get it

Posted: Wed Nov 13, 2013 9:35 am
by Jaka

Hello.

Im bulding an app to get/save/show data from XML. I folowed tutorial http://docs.appery.io/tutorials/build...

and it works fine. The problem is i want to save current state/values in some sort of database or local storage so for example if i close the app or go to another page and come back the values will be there without invoking service.

I tried with local storage and it works with only string but i cant put array in it. What is the easiest way to put data from array to local storage or database and access it . XML I use is like this:

code
<postaja>
<spot>
<postaja>Portorož (09:30)<&#47;postaja>
<veter>E 8&#46;1 KT<&#47;veter>
<sunki>sunki: 14&#46;6 KT<&#47;sunki>
<max>max: 14&#46;6 KT<&#47;max>
<&#47;spot>

<spot>
<postaja>Seča (10:04)<&#47;postaja>
<veter>ENE 18&#46;4 KT<&#47;veter>
<sunki>sunki: 0&#46;0 KT<&#47;sunki>
<max>max: 25&#46;4 KT<&#47;max>
<&#47;spot>
<&#47;postaja>
/code

Keep in mind i have no previous javascript knowlege.


Save array to local storage or database and get it

Posted: Wed Nov 13, 2013 11:44 am
by Kateryna Grynko

Hi Jaka,

You can use the following code:prevar str = JSON&#46;stringify(obj);/preWhere 'obj' is an object or an array.


Save array to local storage or database and get it

Posted: Wed Nov 13, 2013 12:03 pm
by Jaka

Instead of XML i used JSON and saved data to one local storage variable by doing

code
var response = JSON&#46;stringify(data);
localStorage&#46;setItem("json_response", response);
/code

how can i now show some objects in a list?


Save array to local storage or database and get it

Posted: Wed Nov 13, 2013 2:26 pm
by Kateryna Grynko

Jaka,

Not sure we understand. Please clarify what localStorage variable is supposed to be shown in mobilelist component?


Save array to local storage or database and get it

Posted: Wed Nov 13, 2013 3:20 pm
by Jaka

First of all thank you four your answer.

Now my local storage loks like this
code
[{"0":"ILIRSKA BISTRICA",
"1":"11:0:00",
"2":"E",
"":null,
"4":"7&#46;0",
"5":"1&#46;5",
"6":"16&#46;7",
"7":"11:00:00",
"8":"12&#46;5",
"9":"0&#46;0",
"10":null,
"11":"",
"12":"1&#46;11&#46;201",
"spot":"ILIRSKA BISTRICA",
"cas":"11:0:00",
"smer":"E",
"bf":null,
"veter":"7&#46;0",
"sunki":"1&#46;5",
"max":"16&#46;7",
"maxob":"11:00:00",
"temperatura":"12&#46;5",
"padavine":"0&#46;0",
"padavine24":null,
"tmpmorja":"",
"datum":"1&#46;11&#46;201"},

[{"0":"Portorož",
"1":"11:0:00",
"2":"N",
"":null,
"4":"7&#46;0",
"5":"1&#46;5",
"6":"16&#46;7",
"7":"11:00:00",
"8":"12&#46;5",
"9":"0&#46;0",
"10":null,
"11":"",
"12":"1&#46;11&#46;201",
"spot":"Portorož",
"cas":"11:0:00",
"smer":"N",
"bf":null,
"veter":"7&#46;0",
"sunki":"1&#46;5",
"max":"16&#46;7",
"maxob":"11:00:00",
"temperatura":"12&#46;5",
"padavine":"0&#46;0",
"padavine24":null,
"tmpmorja":"",
"datum":"1&#46;11&#46;201"},&#46;&#46;&#46;&#46;&#46;
/code

I would like to make collapsibleset with label1 and inside when is collapsed would be label2.
I would like for each "spot" from local storage (or even better for the one i chose lets say 1,5,7,8 on the list...)to be as label1 and inside of every one would be a label2 with "veter" from local storrage.

I hope you understand me now.


Save array to local storage or database and get it

Posted: Wed Nov 13, 2013 8:42 pm
by Alena Prykhodko

Jaka,

Please check this post, should be helpful https://getsatisfaction.com/apperyio/...