I'm trying to create a service that saves the response into a few local storage arrays. and then on different events map the different local storage array to a listitem.
This way users can use different events to change what results are shown on the list without having to call the service multiple times.
The Venue model contains the parameters that match the fields of the service response exactly.
On the service response I have the JS:
prevar AllArray = [];
var BarsArray = [];
var ClubsArray = [];
for(var i = 0; i < data.length; i++){
AllArray.push(data);
Code: Select all
if(data[i].VenueType == "Bar"){
BarsArray.push(data[i]);
}
if(data[i].VenueType == "Club"){
ClubsArray.push(data[i]); }
}
localStorage.setItem("AllVenues", JSON.stringify(AllArray));
localStorage.setItem("BarVenues", JSON.stringify(BarsArray));
localStorage.setItem("ClubVenues", JSON.stringify(ClubsArray));
/pre
This iterates through the response and puts the data in separate local storage arrays, based on the 'VenueType' db field.
I then map the 'AllVenues' array to a list:
Now, for some reason this doesnt work.
when I test the app, the results are successfully stored in the local storage, but the mapping doesnt work. the list component just isnt there (I have checked the visibility of the list, and I even added a button on the page to set the list visibility property to true, just to make sure that something wasn't hiding the list)
But it still doesnt work. I have the same method on another page and it works there.
Using the same method, I have a similar service on another page that iterates through the response and saves the results in separate storage arrays, with similar code. and then the storage array is mapped to a list component in the same way...
the only difference in the code is:
prevar othernightsArray = [];
var mainnightsArray = [];
for(var i = 0; i < data.length; i++){
if(data.NightName == "Open")
othernightsArray.push(data);
else
mainnightsArray.push(data);
}
localStorage.setItem("OtherNights", JSON.stringify(othernightsArray));
localStorage.setItem("MainNights", JSON.stringify(mainnightsArray));
/pre
I really don't understand why the first example is not working and yet the second one is.