Having trouble with mapping a localStorage variable containing an Array of Objects, which results in the item disappearing

In my localStorage, I have an array called product_categories that contains various objects, each consisting of a string and a nested array of objects representing products belonging to each category.

Despite seeking help from Appery's support team on how to query this array based on attributes within the objects, I decided to organize the data by assigning each product to an array index corresponding to its category.

Currently, I am attempting to display this array of objects in a collapsible block on my page. Previously, I achieved similar functionality with data retrieved from an online database.

Now, using a separate service, my goal is simply to retrieve the array of objects from localStorage and display it in a collapsible block, grid, or list item where each array index creates a new item automatically.

Despite numerous attempts, I have been unsuccessful in mapping the data correctly. The items disappear upon loading the page, almost as if the mapped array has a length of 0.

Upon inspecting the page in Chrome, the localStorage variable holding the array appears valid, matching the format of other variables successfully displayed on the page.

The GenericService I am utilizing pulls the data from localStorage and maps it to the page upon success. However, despite following the same procedure, I am encountering difficulties.

If you find it useful, here is a link to the original Appery.io support page containing relevant images for reference: Appery Support Page

I would greatly appreciate your assistance as communication barriers often hinder progress when interacting with Appery.io's support team

*EDIT Please note that changing 'localStorage' to 'local storage' does not apply in the context of Appery's syntax.

var products = offlineProductList(); // Retrieve JSON array of products
var UniqueCats = $.unique(products.map(function (d) { 
    return d.category // Return distinct categories
}));

var product_categories = []; // Create an array to store category objects and respective products

for(var i=0;i<UniqueCats.length;i++){

    var category_products = []; 

    for(var j=0;j<products.length;j++){

        if(products[j].category == UniqueCats[i]){
            category_products.push(products[j]);
        }

    }
    var category = {"category":UniqueCats[i],"category_products":category_products}; 
    product_categories.push(category); 

}
localStorage.setItem('product_categories', JSON.stringify(product_categories));

Shown below is the code used to generate the 'array of objects'

Mapping Array of Objects

I wish I could provide more information, but due to restrictions, further details are limited. Please feel free to engage if necessary.

Answer №1

After some exploration, I discovered that Appery provides the feature to map expressions on events such as 'Page Load' (for pages/panels etc) and 'Click' (for buttons and similar elements). This allowed me to successfully connect localStorage arrays to list, collapsible, and grid elements. It seems like my issue was with the improper setup of my GenericService. For future users encountering difficulties with mapping something from Storage to the page, simply create a mapping expression from an element's event.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can PHP send a response to Ajax following a 500 error?

While my AJAX function is successfully sending data to a PHP file and displaying the response in my HTML, I have encountered occasional Error 500 responses from the PHP file. Despite knowing the cause of the error, I continue to call the AJAX function agai ...

Tips for attaching to a library function (such as Golden Layout) and invoking extra functionalities

I am currently utilizing a library named Golden Layout that includes a function called destroy, which closes all application windows on window close or refresh. My requirement is to enhance the functionality of the destroy function by also removing all lo ...

Utilizing vue-chartjs to display a pair of data figures side by side

In my vue application, I utilize vue-chartjs to showcase some data and I incorporate semantic-ui for the layout. My goal is to display two figures side by side on the screen, but unfortunately, I am facing difficulties achieving this. I have attempted us ...

Implementing Bootstrap modal functionality in PHP

I'm attempting to trigger a hidden modal from an HTML file using PHP as part of a verification process. One modal is displayed when a button is clicked, while the other is meant to be called by PHP. Below is my PHP code: $File = include("index2.html ...

Implementing IBAN as the default option in Stripe's PaymentElement

The functionality of the react-stripe-js library's IbanElement includes various options such as supportedCountries and placeholderCountry: <IbanElement ... options={{ supportedCountries: ["SEPA"], placeholderCountry: "DE& ...

Error message: The Skeleton Library is unable to extend the 'Array' type with constraints as it does not allow for an inheritance clause

While working on my project and utilizing the SkeletonView library, I encountered an error during the build process... The issue seems to be stemming from a file called RecursiveProtocol.swift Take a look at the contents of this file below: import UIKit ...

Sending an array from the front-end to the back-end in Laravel with JavaScript

I am experiencing difficulty passing a objs array to a function in a Laravel controller using ajax. Unfortunately, I am not receiving any data after the post request. <script> var itemCount = 0; var objs=[]; $(document).read ...

Having trouble with the auto-complete feature in the search box when using Jquery

I'm currently working on implementing TypeAhead functionality for a search textbox. Within the form, I have 2 radio buttons and if one of them is selected, I need the type-ahead feature to populate the list of masters in the search box. //html < ...

Updating JSON data post XMLHttpRequest call

Currently experiencing a puzzling moment. I'm attempting to insert more information into my object after retrieving it from an external source (just for testing purposes, I intend to add random values). Without further ado: As an example, here is w ...

Switches in a React-Native ListView are not refreshing properly

Situation: I encountered an issue with a ListView of Switches Problem: The Switches are not changing state when pressed. When debugging, each switch appears to be checked momentarily after the setValue function is called, but then reverts back to unchecked ...

What is the preferable option between storing data within a class or a JSON file?

I am looking to store user data such as Id: Long, name: String, url: String. There are more than 50k entries. What is the best approach for storing data - inside a data class or JSON file? I am specifically interested in performance and APK size conside ...

Lambda function to update JSON variables

Is it possible to update each value in a JsonNode tree using a lambda expression? { "resource": { "key1": "value1", "key2": "value2", "key3": "value3" } } Attempting to update the values with the following logic: JsonNode ...

Tips for revealing a hidden HTML tag

I am currently trying to validate the content within #textd to ensure it is not empty and contains more than 150 characters. If it meets these conditions, I need to transfer the content to another webpage; otherwise, display an error message based on the c ...

Receiving the error message "Encountered issue reading property of 0" while attempting to retrieve a specific element from an array

Currently, I am facing an issue where I am trying to access a value that is set in one function within another function. When I attempt to return this value at the end, the console.log displays the value correctly. However, when I try to set it, I receive ...

Automated configuration of AWS Amplify JavaScript using Gitpod

Looking to streamline the setup process for an AWS Amplify JavaScript project on Gitpod. My goal is to eliminate the manual steps of configuring the amplify-cli, such as adding IAM users and generating the aws-exports.js file. Successfully installed the a ...

What is the best way to design a Global Navigation menu for websites?

For example, I am looking to integrate a Navigation menu into my website using just one file. I have considered using PHP or creating an HTML frame, but I am wondering what the current industry standard is for professionals. Any insights? ...

Retrieving data from radio buttons using React Hook Form

As I delve into learning React and Next.js, working with form submissions has been a breeze thanks to react-hook-form. However, I've hit a roadblock when it comes to handling radio buttons in my application. Specifically, there's a step where use ...

Retrieving the necessary key values from a JSON dictionary

I'm attempting to retrieve keys from a dictionary using JavaScript. The user uploads a .json file containing the dictionary, and I want to display the keys from that uploaded dictionary. It's important to note that only .json dictionaries can be ...

Dealing with a jQuery/Javascript/AJAX response: sending a string instead of an integer as a parameter to a

Trying to figure out how to handle passing integers as strings in JavaScript within an AJAX response. Here is the code snippet: message+="<td class='yellow' onclick='open_flag("+i+j+")'>"; The message variable is eventually inse ...

Date of latest update on Youtube video

When I was using version 2 of the YouTube API, there was a specific updated tag that provided me with the time when a video was last updated. However, upon transitioning to version 3 of the API, I seem to be unable to locate a similar tag that conveys th ...