I have gone mad trying to bind the json string to the dropdown. Please can somebody help??
My dropdownlist id is 'ddlteams'
My json string is in this form :
"{"TeamList" : [{"teamid" : "1","teamname" : "Barcelona"}]}"
so first i convert into an object.
var objdata = $.parseJSON(jsonObj.d);
Then i add my code given below.
$('#ddlteams').children().remove();
I am having problem with the below code. Please can somebody help me with this
$.each(objdata, function(i, val) {
$('#ddlteams').append('<option value="' + objdata.TeamList[0].teamid + '">' + TeamList[0].teamname + '</option>');
});
objdatais the parsed JSON,iwill be"TeamList"andvalwill be the array. Have a look at the documentation ofeach. Just iterate normally overobjdata.TeamList.$.eachbut it does not seem you know how it works. It will iterate over each property of the object or element of the arrays passed. The property name and its value are passed to the callback function as arguments, in your caseiandval.