JSON response is as follows:
{"approvals":
[
{"approval":
{
"id":"0121920",
"key":"T100",
"value":"Ben Tsu"
}
},
{"approval":
{
"id":"",
"key":"T1000",
"value":"Amy Dong"
}
}
]
}
I’m trying to loop through all properties in the JSON file and match the value of the “key” property passed in as the parameter.
So, to the plugin I’m passing a value “T1000”. If this value exists as an approval “key” value in the JSON file, I want to display the corresponding approval “value” (in this case Amy Dong).
I’m passing inputFieldDefaultValue as a parameter to the plugin with the value being “T1000”. Hence, o.inputFieldDefaultValue.
Here’s my JQuery plugin code but it’s only spitting out object Object, object Object. So, if I have 5 “approval”, this code spits out object Object 5 times.
$.each(response.approvals, function(index, approvals){
if(approvals.approval.key == o.inputFieldDefaultValue){
approvals.approval.value;
}
});
If I do
$.each(response.approvals, function(index, approvals){
if(approvals.approval.key == o.inputFieldDefaultValue){
alert(approvals.approval.value);
}
});
it alerts the corresponding value (Amy Dong) but it still writes object Object (as many times as the properties in the JSON response).
What am I doing wrong?
If I understood you correctly, and all you need is return the
value, you need something like that:I assumed this code is inside some function which is to return the correct value.