javascript - Adding/deleting object properties and removing null -
i trying remember open accordions in custom plugin. first accordion open default, so:
var active = [0];
i click on accordions , read localstorage
values. inside click event:
var active = json.parse(localstorage.getitem(outername)), tab = $(this).find('h3').index(ui.tab[0]); if (tab in active) { delete active[tab]; } else { active[tab] = tab; } (var = 0; < this.length; i++) { if (active[i] == null) { active.splice(i, 1); i--; } } localstorage.setitem(outername, json.stringify(active));
this works, except remove first accordion , click second , i'll duplicated values [1,1]
. have removed null values each time cause don't know how values if toggle accordion removed object.
[0,3]
= accordion 1 , 4 open
[0,1]
= accordion 1 , 2 open
ok patched plugin numbers active strings, modified object because broken:
if (tab in active && active[tab] !== null) { delete active[tab]; } else { active[tab] = tab; }
i getting [null,1,null], overwrite null , replace value [0,1,null] , 0 , 1 read plugin.
so answers own questions quickly!
Comments
Post a Comment