javascript - How do I change the value of a key in localStorage inside JSON? -


i've got calendar. events in calendar written json , stored in localstorage following:

   key = events //all events object    value =            {   "date":"31-3-2015",   "event":"football match",    "participants":"italy - germany",   "description":"support our team friends!"},    "date":"2-4-2015",   "event":"first-night play",    "participants":"famous actors",   "description":"going out theatre gf"}    etc... 

i can change each line of event in calendar. need new value stored in localstorage.

e.g.

  //old version   ""date":"2-4-2015",   "event":"first-night play",    "participants":"famous actors",   "description":"going out theatre gf"}    //edited version   "date":"2-4-2015",   "event":"first-night play",    "participants":"famous actors",   "description":"let gf visit play alone"} 

here's function add new events or edit existing ones:

       var addnewevent = function() {             var events = json.parse(localstorage.getitem('events')) || [];              events.push(             {date: storagenewdate,               event: storageevent,               participants: storageparticipants,               description: storagedescription});               localstorage.setitem('events', json.stringify(events));          }; 

but works ones localstorage (if decide replace existing event new 1 won't reset localstorage), though visually you'll see new event in calendar cell.

so, how refer let's "description" ("event"? "participants"?...) in localstorage in case re-set value?

you storing events array string in localstorage. if want change of values in events, going have replace string value stored in "events" key in localstorage - in other words, replace entire value of events array.

practically, extract values using:

events = json.parse(localstorage.getitem('events')) 

change event want change , save using:

localstorage.setitem('events', json.stringify(events));  

if thinking how change value of single event in "events" in localstorage, have single key "events", can change value whole.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -