Page 3 of 3

How to update Local Storage Array

Posted: Wed Sep 02, 2015 5:27 pm
by Randy7611273

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.


How to update Local Storage Array

Posted: Wed Sep 02, 2015 7:27 pm
by Randy7611273

(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


How to update Local Storage Array

Posted: Fri Sep 04, 2015 1:39 pm
by Serhii Kulibaba

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


How to update Local Storage Array

Posted: Fri Sep 04, 2015 3:44 pm
by Randy7611273

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.


How to update Local Storage Array

Posted: Fri Sep 04, 2015 8:00 pm
by Randy7611273

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'); 
     } 
 } 

});


How to update Local Storage Array

Posted: Sat Sep 05, 2015 2:47 am
by Randy7611273

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; 
             } 
         }

How to update Local Storage Array

Posted: Sat Sep 05, 2015 8:44 am
by Vinny B

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;


How to update Local Storage Array

Posted: Sun Sep 06, 2015 3:11 pm
by Randy7611273

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'); 
     } 
 } 

});


How to update Local Storage Array

Posted: Sun Sep 06, 2015 4:36 pm
by Vinny B

Great Thanks you


How to update Local Storage Array

Posted: Sun Sep 06, 2015 5:12 pm
by Vinny B

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