Retrieving specific information from nested JSON with the help of MVC architecture in backbone.js

I have a good understanding of working with simple concepts using backbone.js, and below is the structure of my nested JSON file:

    {
        "Re":
        {
            "Si":
            [
                {
                    "Def":
                    {
                        "StName": "Gau00",
                        "SID": "1",
                        "Parent": "",
                        "ParentID": "",
                        "Ty": "GAU",
                        "TypID": "2"
                    },
                    "Entities":
                    [
                        {
                            "EntityId": "2003",
                            "Index": "1",
                            "Value": "00"
                        },
                        {
                            "EntityId": "2006",
                            "Index": "1",
                            "Value": "B"
                        },
                        {
                            "EntityId": "2004",
                            "Index": "1",
                            "Value": "B"
                        },
                        {
                            "EntityId": "5",
                            "Index": "1",
                            "Value": "54"
                        },
                        {
                            "EntityId": "9007",
                            "Index": "1",
                            "Value": "1"
                        },
                        {
                            "EntityId": "9703",
                            "Index": "1",
                            "Value": "0"
                        }
                    ],
                    "Connections":
                    [
                        {
                            "SourceID": "2",
                            "DestinationID": "1"
                        }
                    ]
                },
                {
                    "Def":
                    {
                        "StName": "Tan",
                        "ID": "2",
                        "Parent": "",
                        "ParentID": "",
                        "Ty": "TA",
                        "TypID": "3"
                    },
                    "Entities": "",
                    "Connections":
                    [
                        {
                            "SourceElementID": "5",
                            "DestinationID": "2"
                        },
                        {
                            "SourceID": "2",
                            "DestinationID": "1"
                        }
                    ]
                }
        ]
     }  
   }

Now I am looking for ideas on how to retrieve all other details based on the StName from this nested JSON structure using backbone.js. Any suggestions or help would be greatly appreciated.

Answer №1

To solve this problem, start by converting a JSON string into a JavaScript object. Then, implement the following logic:

for each item in "Si":
   if item["Def"]:
       if item["Def"]["StName"] matches "YOUR DESIRED VALUE":
          return item["Def"]

Create a function that accepts your object as an argument, iterates through it, and compares StName with the value you are looking for. If the condition is met, the function should return the current object.

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

Allowing for the acceptance of null values for strings using rapidjson within cereal by assigning them an empty string ""

I am currently using Cereal, which utilizes RapidJSON, to deserialize JSON into a C++ class. In my case, the issue arises because c++ std::string does not allow for null values. However, other platforms such as .NET and SQL do support null values for strin ...

Adding a PHP input to the image source

I am currently working on a project that involves creating an image based on the genre retrieved from an icecast server. I believe my initial code is accurate, but I suspect there might be an issue with how I have implemented the PHP variable. <?php ...

Is there a way to add a fade-in and slide-in effect to this dropdown JavaScript, as well as a fade-out and

Although I lack the necessary knowledge of Javascript, I am aware that my request may be a bit much. The code I currently have is directly from the w3school dropdown-list demo. Would it be possible for you to help me implement a fade in and slide in effect ...

Understanding how to access a variable outside of a function in Node.js can be crucial for successfully passing

I am trying to figure out how to access the TRADE_OUT variable outside of a specific function in my application. Despite my efforts, I haven't been successful so far. I need the value of TRADE_OUT to be globally accessible within the entire applicatio ...

Shift the element within the div towards the left side

I am trying to create an animation for an element that moves to the left when hovered over, but the code I thought was correct doesn't seem to be working in my fiddle. Here is the link to the fiddle I created: https://jsfiddle.net/feb8rdwp/3/ Based ...

Displaying concealed fields using the Bootstrap table detail formatter

I am attempting to create a customized detail formatter for my table, but I am encountering several fields with underscores, such as: _id: undefined _class: undefined _data: [object Object] This occurs when I click the plus button. <head> &l ...

Using PHP, JavaScript, and Bootstrap to display success or error messages for form fields through AJAX

I am working on a form where users input an 'authorisation code' that is then checked against a database using AJAX and PHP. Currently, the form displays a tick if the code is valid and a cross if it is incorrect. I would like to utilize Bootstra ...

Optimizing Wordpress by Efficiently Enqueueing Javascript

As a beginner with a WordPress website, I am aware that in order to execute scripts on a WordPress page, they need to be enqueued in the functions.php file. However, I'm unsure about the correct process for this. The specific JavaScript file I want t ...

Struggling to reflect changes in the database using the updated value in the localStorage

I have a table where the td is set to contenteditable. To update the value of the td in my database, I decided to use localStorage. When the save button is clicked, the inputted value in the td will be saved to localStorage and retrieved via AJAX to replac ...

Issue with the demo code for Vue Stripe Checkout

As I delve into the world of Vue-Stripe-Checkout, I encountered a snag right from the start with the demo code provided. The issue arises when utilizing the Vue Stripe Elements component. Has anyone else experienced this problem? There are no errors displa ...

What could be causing my ng-class specified directive to not be recognized in AngularJS?

check out this plunker link I am facing a challenge where I need to incorporate a directive as a class in my code. Specifically, I want to use the following pattern: ng-class='{"some-directive":1'} However, the directive can only be registered ...

Step-by-step guide on how to change the appearance of a <DIV> using data from a database (JSON

After retrieving data from a database as a JSON file, I have written code to loop through an item (portOn) and determine if certain ports are present in the array. If a port is found in the array, its corresponding variable is set to true. var portG01,port ...

Angular: Error encountered due to a SyntaxError caused by an unexpected token < appearing in JSON at position 0

Hey there, I need some assistance. I've created an Angular service but when I try to access data from my JSON file, I keep encountering errors. I've tried several solutions without success. Here is the code in app.component.ts: import {Comp ...

Display the hover effect for the current card when the mouse is over it

When the mouse hovers over a card, I want only that specific card to show a hover effect. Currently, when I hover over any card, all of them show the hover effect. Is there a way to achieve this in Vue Nuxtjs? Here's what I am trying to accomplish: ...

WordPress REST API - Issue with New Category returning undefined, yet still able to be accessed

Currently, I am utilizing the WordPress REST API and have successfully created a new category. However, when making queries to the API, it is returning undefined for that particular category. Upon visiting: /wp-json/wp/v2/categories, category 17 does not ...

Unable to execute functions due to a type error in Discord.js

An issue has arisen: TypeError: Cannot read properties of undefined (reading 'add') line 40 I've searched extensively, including the discord API, but couldn't find a solution. If there are any improvements I can make to my code, plea ...

Are Json.load operations considered inefficient?

While browsing through the json module's source code in search of an answer to another question, I stumbled upon something quite intriguing. After removing the docstring and various keyword arguments, the essence of json.load is revealed as follows: ...

Is there a way to retrieve the properties of another function within the same component?

I am trying to place NumberFormat inside OutlinedInput and I also need different properties for the format of NumberFormat. (There will be a select window that defines which format property to use). This is what I have: import OutlinedInput from "@ma ...

Currently, I am working on a toggle feature and am looking to alter the background color of a div when the toggle function is triggered

Here is the function I'm working with: function toggleDiv() { let targetDiv = document.getElementById('targetDIV') if (targetDiv.style.display === 'none') { targetDiv.style.display = '' } else { targetDi ...

Transforming a fluid webpage into a fixed page

Currently, I am undertaking a project that involves converting a dynamic website like Adobe Spark into a static HTML+CSS page, which will eventually be transformed into a PDF. The interactivity of the website relies heavily on Javascript modifying CSS+HTML ...