jquery - remove item from localStorage -


i'm trying remove item localstorage. when user clicks on delete button, need examine contained in localstorage , remove value based on row deleted.

for example, localstorage contains following comma delimited list:

contact,user,account 

if row deleted account row, need remove account value list localstorage contain:

contact,user 

or, if row deleted user row, need remove user value list localstorage contain:

contact,account 

here jquery code:

<script type="text/javascript">      var j$ = jquery.noconflict();      j$(document).ready(function() {         var datarows = j$('tr.datarow');         localstorage.activebuttons = '';                   var active = localstorage.activebuttons.split(',');                   datarows.each(function(index, elem) {             updateimages(elem, active[index]);         });          j$("img[id$=':deleteimage']").on("click", function(event) {             updateimages(j$(this).closest('tr'));         });          j$('[id$=btncontact]').on('click', function() {             localstorage.activebuttons += 'contact,';         });          j$('[id$=btnuser]').on('click', function() {             localstorage.activebuttons += 'user,';         });          j$('[id$=btnaccount]').on('click', function() {             localstorage.activebuttons += 'account,';         });          a4j.ajax.addlistener({             onafterajax: function(req,evt,data) {                    console.log('************* activebuttons = ' + localstorage.activebuttons);                 j$('[id$=deleteimage]').on('click', function(elem) {                     console.log('the delete button clicked');                     console.log(elem);                     console.log('************** before ' + localstorage.activebuttons);                     localstorage.activebuttons = localstorage.activebuttons;                     console.log('************** after ' + localstorage.activebuttons);                 });                 console.log('************* activebuttons = ' + localstorage.activebuttons);                  var lastrow = j$('table[id$=participanttable] tbody tr:last');                                  var active = localstorage.activebuttons.split(',');                  var datarows = j$('tr.datarow');                 datarows.each(function(index, elem) {                     updateimages(elem, active[index]);                 });             }         });         });      function updateimages(myrow, myactive) {          var rowinputs =  j$(myrow).find('input[type="text"]');         var contactid = (j$(rowinputs[0]).attr('id'));         var userid = (j$(rowinputs[1]).attr('id'));         var accountid = (j$(rowinputs[2]).attr('id'));         var contact = (j$(rowinputs[0]).val());          var user = (j$(rowinputs[1]).val());         var account = (j$(rowinputs[2]).val());          if(contactid.indexof("participant") != -1 || userid.indexof("participant") != -1 || accountid.indexof("participant") != -1) {             switch (myactive) {                 case "contact":                     // hide other 2                     j$(rowinputs[1]).hide();                     j$(rowinputs[2]).hide();                     j$(rowinputs[1].parentnode).find('img').hide();                     j$(rowinputs[2].parentnode).find('img').hide();                     break;                 case "user":                     // hide other 2                     j$(rowinputs[0]).hide();                     j$(rowinputs[2]).hide();                     j$(rowinputs[0].parentnode).find('img').hide();                     j$(rowinputs[2].parentnode).find('img').hide();                     break;                 case "account":                     // hide other 2                     j$(rowinputs[0]).hide();                     j$(rowinputs[1]).hide();                     j$(rowinputs[0].parentnode).find('img').hide();                     j$(rowinputs[1].parentnode).find('img').hide();                     break;             }             if (contact !== '') {                 j$(rowinputs[1]).hide();                 j$(rowinputs[2]).hide();                 j$(rowinputs[0].parentnode).find('img').show();                 j$(rowinputs[1].parentnode).find('img').hide();                 j$(rowinputs[2].parentnode).find('img').hide();             }                 else if (user !== '') {                 j$(rowinputs[0]).hide();                 j$(rowinputs[2]).hide();                 j$(rowinputs[0].parentnode).find('img').hide();                 j$(rowinputs[1].parentnode).find('img').show();                 j$(rowinputs[2].parentnode).find('img').hide();             }             else if (account !== '') {                 j$(rowinputs[0]).hide();                 j$(rowinputs[1]).hide();                 j$(rowinputs[0].parentnode).find('img').hide();                 j$(rowinputs[1].parentnode).find('img').hide();                 j$(rowinputs[2].parentnode).find('img').show();             }             if (account !== '' && contact !== '') {                 j$(rowinputs[1]).hide();                 j$(rowinputs[2]).show();                 j$(rowinputs[0].parentnode).find('img').show();                 j$(rowinputs[1].parentnode).find('img').hide();                 j$(rowinputs[2].parentnode).find('img').hide();             }         }     } </script> 

here relevant portion of code i'm trying remove value localstorage:

        a4j.ajax.addlistener({             onafterajax: function(req,evt,data) {                    console.log('************* activebuttons = ' + localstorage.activebuttons);                 j$('[id$=deleteimage]').on('click', function(elem) {                     console.log('the delete button clicked');                     console.log(elem);                     console.log('************** before ' + localstorage.activebuttons);                     //here need remove value localstorage                           //i passing in elem function argument determine                           //what row being deleted , value should remove                            //local storage.                     console.log('************** after ' + localstorage.activebuttons);                 });                 console.log('************* activebuttons = ' + localstorage.activebuttons);                  var lastrow = j$('table[id$=participanttable] tbody tr:last');                                  var active = localstorage.activebuttons.split(',');                  var datarows = j$('tr.datarow');                 datarows.each(function(index, elem) {                     updateimages(elem, active[index]);                 });             }         }); 

any appreciated. thanks.

split values array, find value want remove, , splice array:

var activearray  = localstorage.activebuttons.split(','); var idx = activearray.indexof(elem); // not sure elem is, should value want remove  if (idx > -1)     activearray.splice(idx, 1);  localstorage.activebuttons = activearray.join(','); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -