Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

How to update Local Storage Array

I tried the code above. No alert is presented. I also tried the code sent via email:

----

Randy,

You have you use JS like this:

for (var i = 0; i < currecord.length; i++){
console.log("a_id="+currecord.a_id);
}

----

Message "a_id=undefined" is presented.

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

How to update Local Storage Array

(1) Generic service 1 filters local array for objects containing only votedReturn items equaling “false” and is mapped to list. (This works).
(2) Clicking on “vote” button sets local storage variable id for the clicked item on the list. (This works).
(3) Generic service 2 finds the clicked item id and maps to test list. Local storage variable id and array object item a_id equal at this point. (This works)
(4) votedReturn item in the same object as a_id where it equals id needs to be changed to “true” (This does not work!) Image Image

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to update Local Storage Array

I am sorry, not sure I understand you correctly. Please specify your question.

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

How to update Local Storage Array

Where _id is clicked, I need the array index for a_id. None of your recommendations have worked. The below code works:

-----

var liveEventArray = Apperyio.storage.liveEventArray.get();
//here you can alter your array in way you need. Like:
liveEventArray[0].votedReturn = "true";
Apperyio.storage.liveEventArray.set(liveEventArray);

-----

However, I need liveEventArray[0] to instead be liveEventArray[x], where "x" is a variable equal to the selected array object index, as detailed in my screenshots above.

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

How to update Local Storage Array

Below is the latest code I'm trying. It is returning console.log (i, "index fail"); each time:

-----

Appery.localService2JS = Appery.createClass(null, {
init: function(requestOptions) {
this.requestOptions = $.extend({}, requestOptions);
},
process: function(settings) {
if (this.requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
var cdata = Apperyio.storage.liveEventArray.get();
var thisVote = (localStorage.getItem("_id"));
var searched = thisVote;
console.log(cdata);

Code: Select all

        var match = cdata.filter(function arrayObjectIndexOf(cdata, searched, a_id) { 
             for (var i = 0, len = cdata.length; i < len; i++) { 
                 if (cdata[i][a_id] === searched) return i; 
                 console.log (i, "index"); 
                 liveEventArray[i].votedReturn = "true"; 
             } 
             console.log (i, "index fail"); 
             return -1; 
         }); 

         settings.success(match); 
         settings.complete('success'); 
     } 
 } 

});

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

How to update Local Storage Array

Almost there!!! Code below returns console.log(x, "postion"); with "position: 0 postion." However, cdata[x].votedReturn = "true"; errors with "TypeError: Cannot set property 'votedReturn' of undefined(...)"

-----

for (i = 0; i < cdata.length; i++) {
if (cdata.a_id === searched) {
//alert('position: ' + i);
var x = ('position: ' + i);

Code: Select all

                 console.log(x, "postion"); 

                 cdata[x].votedReturn = "true"; 

                 Apperyio.storage.liveEventArray.set(cdata); 
                 return; 
             } 
         }
Vinny B
Posts: 0
Joined: Fri Aug 22, 2014 2:22 pm

How to update Local Storage Array

I too would like an answer to this question. I get the same error.
var grid = Apperyio('grid').text();
var arrayVal = Apperyio('arrayVal').text();

var liveEventArray = Apperyio.storage.fireCalendarArray.get();
//here you can alter your array in way you need. Like:

liveEventArray[arrayVal].(grid) = gridOutput;

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

How to update Local Storage Array

For those of you playing along at home, here is the complete and working code. Thanks to those who provided assistance.

-Randy

Appery.localService2JS = Appery.createClass(null, {
init: function(requestOptions) {
this.requestOptions = $.extend({}, requestOptions);
},
process: function(settings) {
if (this.requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
var cdata = Apperyio.storage.liveEventArray.get();
var thisVote = (localStorage.getItem("_id"));
var searched = thisVote;

Code: Select all

         // identify clicked item and set to true 
         for (i = 0; i < cdata.length; i++) { 
             if (cdata[i].a_id === searched) { 

                 var x = (i); 
                 //console.log(x, "postion"); 
                 cdata[x].votedReturn = true; 
                 Apperyio.storage.liveEventArray.set(cdata); 
                 //return; 
             } 
         } 

         // test list display 
var searched1 = true;  
         var match = cdata.filter(function(item) { 
             return item.votedReturn === searched1; 
         }); 

         settings.success(match); 
         settings.complete('success'); 
     } 
 } 

});

Vinny B
Posts: 0
Joined: Fri Aug 22, 2014 2:22 pm

How to update Local Storage Array

Great Thanks you

Vinny B
Posts: 0
Joined: Fri Aug 22, 2014 2:22 pm

How to update Local Storage Array

Is it possible to make voteReturn dynamic? So I can change the value of it and effect different columns in my array

Return to “Issues”