Using underscore.js to connect an object with $rootscope: a step-by-step guide

I have a variable storing data

var tooltipsJson = [{
    "Language": "en-GB",
    "Section": "Sales&Marketing",
    "ItemName": "CalculationType",
    "Texts": "Having selected the account heading select the calculation ..."
  },
  {
    "Language": "en-GB",
    "Section": "Taxes",
    "ItemName": "Save",
    "Texts": "The Master Tax Table has been pre populated with the current UK, ..."
  }
];

and I am looking to utilize underscore.js each

_.each(.........)

when I input:

console.log({{tooltipsJson.Taxes.Save}});

to show the text

The Master Tax Table has been pre populated with the current UK, ...

My goal is to assign the Texts attribute to a local variable

Answer №1

Give it a shot:

$scope.data = {};

_.forEach(tooltipsData, function( value, index ) {
    $scope.data[index] = value;
});

Answer №2

To output all the "Texts" attributes of the elements in the array, you can use the .each() method as shown below:

_.each(tooltipsJson, function(element){
    console.log(element.Texts);
});

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

Exploring Angular2: A Guide to Interpolating Expressions in Templates

Is it possible to interpolate different types of Javascript expressions? Along with displayed properties like object.property and short expressions such as {{1+1}}, what other valid Javascript expressions can be used for interpolation? ...

Using Asynchronous JavaScript and XML (AJAX) to make calls to a web service

My program is showing an internal server error var parameters = "<?xml version='1.0' encoding='utf-8'?>" + "<soap:envelope xmlns:xsi='ttp://www.w3.org/2001/xmlschema-instance' xmlns:xsd='http://www.w3. ...

The issue arises from the fact that the Bootstrap modal fails to open automatically

Having trouble getting my bootstrap modal to open on page load, even though the button to trigger it is working fine. Here is my code: <div id="myModal" class="modal fade" role="dialog"> <div class=" ...

Error message encountered: "When fetching JSON data in React Native, the error 'undefined

== UPDATE == I'm facing an issue with fetching a JSON data. I am trying to retrieve a JSON from Google Maps, but it is returning as undefined. Here is the code snippet: const [isLoading, setLoading] = useState(true); const [info, setInfo] = u ...

Is it possible to store an HTML element tag in a variable?

I've been learning JavaScript on w3schools and freecodecamp, but I stumbled upon something in w3schools that has me puzzled. Can someone please explain why this particular code snippet works? The variable "text" is declared as containing the string " ...

Connecting angular-cli to WebStorm

I am facing an issue with npm where it's not linking the global modules to command line. Angular-cli has been installed as a global module but WebStorm is unable to locate it. Is there a way to instruct WebStorm on where to look for angular-cli? ...

Using JQuery, identify cells located in the first column of a table excluding those in the header section

In the past, I had code that looked like this: $(elem).parents('li').find(...) I used this code when elem was an item in a list, making it easy to reference all items in the list. But now, I've made some changes and decided to use a table ...

Can I add the object to the DOM and hold off on executing any events until the next

Just came across this intriguing interview question (shown below). Could someone please provide an explanation of the question and then offer a solution? Develop a function that takes an object and adds it to the DOM, ensuring that events are stored unt ...

Traditional method for comparing prevProps in componentDidUpdate

As I work on prototyping, I've noticed that when new props come in as an array of complex objects, prevProps.myProp===this.props.myProp always returns false. While using JSON.stringify for comparison seems to work, it doesn't feel very reliable. ...

Deliver real-time notifications to linked users by leveraging socket.io and node.js

Is there a solution for sending real-time updates to connected clients every second without using the setInterval() function in nodejs and socket.io? Please provide an alternative method that fits my specific scenario. ...

Exploring the metadata of a JSON file using Python

I am seeking guidance on how to specifically access metadata from a JSON file in Python. My goal is to efficiently read or generate a separate metadata file for the JSON data, which will assist me in identifying top-level keys and field names/column names ...

Storing data on the server for your Cocos2d JavaScript game

I've been struggling with implementing a savegame option for my cocos2d JavaScript game. After following a tutorial from Ray Wenderlich (thanks, Ray!), I gave up on trying to do it client-side and am now looking into saving XML files to a web server w ...

Having trouble accessing properties of an undefined object when trying to read 'credentials' in Firebase Auth within ReactJS

I need to verify the user's password again before allowing them to change it. Currently, my Firebase Auth setup is defined in Firebase.js and exported correctly //appConfig = ...(all the configurations here) const app = firebase.initializeApp(appConf ...

standards for matching patterns (such as .gitignore)

Throughout my experience, I have utilized various tools designed to search a codebase for specific files and then carry out operations on those files. One example is test libraries that identify all the necessary files for execution. Another common tool is ...

Struggling to extract specific information from a json array using Angular, my current approach is only retrieving a portion of the required data

My JSON structure is as shown in the image below: https://i.stack.imgur.com/5M6aC.png This is my current approach: createUIListElements(){ xml2js.parseString(this.xml, (err, result) => { console.log(result); this.uiListElement = result[ ...

What is the recommended approach for including XML within JSON for an HTTP Response?

I am currently working on a project that requires me to send back a JSON object in an HTTP response, where one field contains an XML snippet as a value. Below is an example of how the object would be structured: { "driver1_url" : "https://driver.url.dow ...

Dynamically loading an AngularJS controller

I am faced with the challenge of integrating an Angular app with dynamically loaded controllers into an existing webpage. Below is a code snippet where I have attempted to achieve this based on my understanding of the API and some research: // Create mod ...

Using a combination of StringTokenizer, JSON, and commas to parse and manipulate data

My Android project is encountering an issue when trying to read strings with commas within a JSON object. The initial JSON string that works fine is as follows: {"success": "[TG2301_Stoke Holy Cross, TF7439_Thornham Corner, TL8583_Thetford]"} However, pr ...

What could be causing the state object in React to not be updating correctly? There seems to be a discrepancy between the expanded and

Displayed on the console is a screenshot showing <br><br> I am working with React.js, and the object displayed in the image is an element within an array that is part of the state object. I'm puzzled by what's happening. The object a ...

Avoiding memory leaks in Node.js with Express framework

Dealing with memory leaks in nodejs (express.js) has been a challenge for me. I followed various tutorials online, but unlike the examples provided, identifying the source of the leak in my code has not been straightforward. Through the use of Chrome Dev T ...