I have a fairly large JSON file and I wish to loop through certain keys with Jquery.
How would I use a variable ( "countrySelector" in the example below) in my $.each loop so I only filter through the relevant key/selector.
Here is my JSON layout
{ - world_projects: {
- australia: {
- {
project_id: 123
},
- {
project_id: 456
},
},
- usa: {
- {
project_id: 789
},
- {
project_id: 022
},
},
}
Here is my Jquery code:
jQuery(document).ready(function($) {
// Grab the country
var countrySelector = $( '#map-projects-wrapper' ).data('country');
// Get our JSON file which contains all collections
// and project information
$.getJSON( "projects.json", function( jsonData ) {
// Cycle through each Project
$.each( jsonData.world_projects.countrySelector, function( project_key, projects ) {
// here I would do my thing
}
}
});
I hope that makes sense,
Thank you Chris.