I am trying to figure out how to select specific JSON objects when a line item meets a variable or variables that is passed on button click. So far, I get it to work but it says [object],[object]. I believe this is because it is returned in an array. What am I missing?
var Type = "Champagne";
$(document).ready(function(){
$("button").click(function(){
$("#data-details").empty();
$.get("working-data-file.json",{Type: Type},function(result){
$.each(result.data, function(i, field){
$("#data-details").append(this.objects.Title);
});
});
});
});
The .JSON file looks like this:
{"objects":
[
{
"Type": "Champagne",
"Sweetness": "Brut",
"Producer": "Dom Perignon",
"Vintage": "2006",
"Recommendation": "Classic",
"Data": "12.29.2012",
"Title": "The wine’s opulence – contained and succulent, round at heart – reveals itself in the mouth."
},
{
"Type": "Cava",
"Sweetness": "Brut-Nature",
"Producer": "Canals Canals",
"Vintage": "2014",
"Recommendation": "Preferred",
"Data": "12.29.2012",
"Title": "2nd Cava."
}
]
}
jsondata?$.each(result.objects,function(k,v){//your code})this will solve your problem just give it try