I have a large JSON file with a snippet of the file below. Please ignore the values as they are only used as placeholders for this question.
"restaurants":[
"name": "Burger King",
"location": "Seattle, WA",
"latitude": 0.000,
"longitude": 0.0000,
"server": "BKSEATAC1",
"serverAddress": "127.0.0.1",
"taskNames": ["BurgerOne","BurgerTwo","BurgerThree"],
"currentTasks": ["BurgerOne"],
"tasks": [ {"name":"BurgerOne","owner":"Tom","startTime":"11:00","endTime":"11:05","duration":"5"},
Using jQuery, I am able to iterate through the "restaurants" and set values for variables in the following manner:
$.getJSON('json/DATA.json', function(data) {
$.each(data.restaurants, function(key, val) {
var restaurantName = this.name;
var restaurantLocation = this.location;
(Please note that the code above is just a snippet)
To iterate through the "inner" JSON starting at "tasks", I use the following code
$.getJSON('json/DATA.json', function(data) {
$.each(data.restaurants, function(key, val) {
$.each(val.tasks, function(i, j){
var taskName = this.name;
var taskOwner = this.owner;
(Another snippet)
The problem I am having is that if I combine the code, variables are assigned correctly in the first iteration but not the second. The loop iterates through "restaurants" and then executes the rest of the code in the script and only then iterates through the "tasks". I need all the variables set on the first pass. Any tips or suggestions would be appreciated.
Thanks in advance!
I have three sliding panels in my html. The thing is that panels overlay each other when open. I would like to get a function that create an event when one panel (eg. #panel1) is open already and the ...
I have three sliding panels in my html. The thing is that panels overlay each other when open. I would like to get a function that create an event when one panel (eg. #panel1) is open already and the ...
I have a Meteor method that I call from the client, which in turn updates all fields in a single document. In the last line of code below I try to immediately run the same update on the client to get ...
I have a Meteor method that I call from the client, which in turn updates all fields in a single document. In the last line of code below I try to immediately run the same update on the client to get ...
I'm trying to create a select list control that supports data with a tree structure and has typeahead capability. The data looks like this: Category -> SubCategory Category2 -> ...
I'm trying to create a select list control that supports data with a tree structure and has typeahead capability. The data looks like this: Category -> SubCategory Category2 -> ...
I'm using the Twitter oembed api, and now have the following code on my page: <div class='row'> <iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" ...
I'm using the Twitter oembed api, and now have the following code on my page: <div class='row'> <iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" ...