I'm loading the following json file from a url:
{
"Airports": [
{
"listing": "East 34th Street Heliport",
"iata": "TSS",
"type": "heliport",
"size": "tiny"
},
{
"listing": "Blaine Municipal Airport",
"iata": "BWS",
"type": "closed",
"size": "small"
},
{
"listing": "Toronto City Airport",
"iata": "YTZ",
"type": "airport",
"size": "medium"
},
{
"listing": "Amsterdam Airport Schiphol",
"iata": "AMS",
"type": "airport",
"size": "large"
},
{
"listing": "Detroit County Airport",
"iata": "DTW",
"type": "airport",
"size": "large"
}
]
}
And I want to go through the Airports array and display all key names and values on the DOM. I do this in a .each() loop using jquery mobile :
if(pageID == "page1"){
var pageTitle="Error";
//temp var to hold collapsible HTML
var colItem="";
$.ajax({
url:"some_url",
method:"GET",
cache:false,
dataType:"json",
success:function(data){
pageTitle = (Object.keys(data)[0]).toUpperCase();
$(data.Airports).each(function(index,value){
//build all the needed collapsibles
colItem +=
"<div data-role='collapsible'><h2>"
+ value.listing +
"</h2> <p>"
+ +
"</p> <p>"
+ +
"</p> <p>"
+ +
"</p></div>";
});
}
});
Is there a way to do this without referencing the key values such as what I have done using value.listing but instead iterate through it like an array an get all the values that way.
I'm looking for a final result similar to this:
East 34th Street Heliport
iata TSS
type heliport
size tiny