I have a jqGrid
control which includes a dropdownlist field. The items in the list come from a method on the server side using ajax
, but I'm not sure how to structure the returned json
to make it compatible with the grid. I looked at this question and according to the answers, it seems like the grid expects the following format for dropdowns:
[value] : [display text]
I'm relatively new to JavaScript and am not sure what type of data this is (I'm assuming it's a key-value pair?) so I don't know how create an array of this type from my json object. This is what I tried:
function populateTable(){
$.ajax({
type: "POST",
url: "MyHttpHandler.ashx",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
var jsonObject = jQuery.parseJSON(result.d);
var dropdpwnvalues = new[];
for(var i = 0; i< jsonObject.length; i++){
dropdpwnvalues.push({ jsonObject[i].id : jsonObject[i].name });
}
// The rest of the function
);
}
dropdpwnvalues
variable is the one that gets bound to the grid. Note that jsonObject
does have an id
and name
on it, but this syntax
dropdpwnvalues.push({ jsonObject[i].id : jsonObject[i].name });
is obviously incorrect. Any ideas how I can make the list from this json object?