Page 2 of 4

saving an array in localstorage

Posted: Wed Nov 21, 2012 11:43 am
by Maryna Brodina

Hi!

Please try this code save(Tiggzi('component_name').attr('text'), 'variable_name') instead of save(Tiggzi('component_name').text(), 'variable_name')

Let us know if it helps


saving an array in localstorage

Posted: Wed Nov 21, 2012 11:53 am
by Michael4771079

Hi Marina,

this is the result
variable_favourites

"["","","","","","","","","","",null,null]"


saving an array in localstorage

Posted: Wed Nov 21, 2012 1:45 pm
by Maryna Brodina

Add one more part of JS to JS asset. Whole JS should look like this:

codefunction setSelectMenuOptions(select, options) {
select.children().each(function() {$(this).remove()});
for(i=0; i<options&#46;length; i++) {
var value = options;
var newOption = $('<option value="'+value+'">'+value+'<&#47;option>');
select&#46;append(newOption);
}
select&#46;refresh();
}

function save(item, varName) {
var arr = JSON&#46;parse(localStorage&#46;getItem(varName));
if(arr == null) {
arr = new Array();
}
arr&#46;push(item);
localStorage&#46;setItem(varName, JSON&#46;stringify(arr))
}

function myload(varName) {
var arr = JSON&#46;parse(localStorage&#46;getItem(varName));
if(arr == null) {
arr = new Array();
}
return arr;
}/code

Put this code on button to save array

codesave(Tiggzi('mobiletextinput1')&#46;val(), 'variable_name')/code

Put this code on button to update valued in select menu

codesetSelectMenuOptions(Tiggr('mobileselectmenu2'), myload('variable_name'));/code

On scrin Load run Customm JS to refresh values

codelocalStorage.setItem('variable_name', null);code
/code/code


saving an array in localstorage

Posted: Wed Nov 21, 2012 1:54 pm
by Michael4771079

Sorry for this Marina,
do you mean in custom java instead of this

dofunction save(item, varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr))
}

function myload(varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
return arr;
}


saving an array in localstorage

Posted: Wed Nov 21, 2012 1:59 pm
by Maryna Brodina

Yes:)


saving an array in localstorage

Posted: Wed Nov 21, 2012 2:45 pm
by Michael4771079

no Marina, no change on select menu, result in firebug local storage
variable_favourites "null"

-


saving an array in localstorage

Posted: Wed Nov 21, 2012 3:00 pm
by Maryna Brodina

Please check components name, are they correct?

http://project.tiggzi.com/mobile-fram...


saving an array in localstorage

Posted: Wed Nov 21, 2012 4:01 pm
by Michael4771079

no luck Marina,
I followed the detail, but I can't get it to work


saving an array in localstorage

Posted: Wed Nov 21, 2012 4:22 pm
by Maryna Brodina

What builder do you use?


saving an array in localstorage

Posted: Wed Nov 21, 2012 4:39 pm
by Michael4771079

the new builder