Note that there are some explanatory texts on larger screens.

plurals
  1. POLocal storage Javascript and JSONArray
    primarykey
    data
    text
    <p>I'm trying to storage data locally with JSONArrays and Objects. What the program does is get the value of several sliders i have inserted dynamically (sometimes 1, sometimes 2 sliders and sometimes 3 or 4...). So I get the values and the id of the product to store locally with arrays. <strong>But there's a problem It only saves the first array, the push method doesn't work.</strong></p> <p>Here's the code:</p> <pre><code>function afegir_i_editar_llistacompra(){ //Obtenim els valors dels sliders i els guardem a localhost var id_product = $('body').data('product'); var array_of_bought_colors_new = new Array({'id': id_product}); var array_of_bought_colors_existing = get_product_info(id_product, 'cesta_list'); for (var i = 0; $('#slider-'+i).val() != null ; i++) { array_of_bought_colors_new.push({'color':$('#slider-'+i).attr('name'),'value': $('#slider-'+i).val()}); }; if(array_of_bought_colors_existing != null){ for (var i = array_of_bought_colors_existing.length - 1; i &gt;= 1; i--) { if(array_of_bought_colors_existing[i].value != array_of_bought_colors_new[i].value) array_of_bought_colors_existing[i].value = array_of_bought_colors_new[i].value; }; }else if( array_of_bought_colors_new.length &gt; 1 &amp;&amp; $('body').data('cesta_list') != null) { $('body').data('cesta_list', $('body').data('cesta_list').push(array_of_bought_colors_new)); }else{ $('body').data('cesta_list', array_of_bought_colors_new); } } </code></pre> <p>What I'm saving:</p> <pre><code>[{id:1},/*First slider --&gt;*/{'color':'blue','value':2},/*Second slider --&gt;*/{'color':'blue','value':32}] </code></pre> <p>Hope you understand!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload