使用jqGrid ver 5.0.1
我很难使用buildSelect函数获取选择列表。我在SO上尝试了很多解决方案,但似乎都有同样的问题 - 列表中填充了“未定义”。这是我目前的代码:
{name: "Status", width: 150,
editable: true, edittype: "select",
editoptions: {
dataUrl: "Handler3.ashx",
buildSelect: function (data) {
alert(data);
var select = '<select>', i, l = data.length, item;
for (i = 0; i < l; i++) {
item = data[i];
select += '<option value="' + item.value + '">' + item.name + '</option>';
}
return select + '</select>';
}
}
},
dataUrl(在警报处)返回的数据如下:
[{"value":6,"name":"ASSIGNED"},{"value":16,"name":"BLANK"},{"value":14,"name":"CANCELLED"},{"value":3,"name":"COMPLETE"},{"value":15,"name":"HOLD 1ST QTR"},{"value":5,"name":"NEW"},{"value":8,"name":"NOTE"},{"value":7,"name":"ON HOLD"},{"value":4,"name":"PRODUCTION"},{"value":11,"name":"PROPOSED SOLUTION"},{"value":13,"name":"STAGING"},{"value":12,"name":"TESTING"},{"value":9,"name":"WAITING"},{"value":10,"name":"WORKING"}]
Handler3.ashx中的代码只是执行SQL选择并返回数据:
SqlDataAdapter adapter = new SqlDataAdapter("SELECT LKPID AS value, LKPDESC AS name FROM dbo.PRJLOOKUPS WHERE LKPTYPE = " + "'SCD'" + " AND LKPRSPO <> " + "'INACTIVE'" + " ORDER BY LKPDESC", con);
adapter.Fill(ds);
int num = ds.Tables[0].Rows.Count;
context.Response.ContentType = "application/json";
context.Response.Write(JsonConvert.SerializeObject(ds.Tables[0]));
我还尝试在处理程序中调用SQL存储过程,以在Ajax调用中返回格式化字符串,并在加载完成时设置编辑选项值。返回的字符串是:
[{"Column1":"6:ASSIGNED;16:BLANK;14:CANCELLED;3:COMPLETE;15:HOLD 1ST QTR;5:NEW;8:NOTE;7:ON HOLD;4:PRODUCTION;11:PROPOSED SOLUTION;13:STAGING;12:TESTING;9:WAITING;10:WORKING"}]
这有点作用,但列表中的第一项看起来像“已分配,最后一个看起来像工作”}}
有人能指出我使用buildSelect做错了什么吗?
答案 0 :(得分:0)
alert(data)
应该无法显示正确的返回数据。它应该只显示&#34;类型对象&#34;。如果您按alert(data)
查看字符串,则可以按使用情况修复问题
data = $.parseJSON(data);
直接在buildSelect
的开头,处理数据之前。