问题描述
这是在<延续href=\"http://stackoverflow.com/questions/30981085/how-to-pass-parameter-to-editoptions-dataurl-method-for-edittype-select-for-in/30981678?noredirect=1#comment50022434_30981678\">this线。我使用的自由的jqGrid 4.9.0 并有内联编辑。
{名称:'联系人姓名',可编辑:真,宽度:100,排序:假的,冷冻的:真实,格式:'选择',edittype:'选择',
editoptions:{
dataUrl:'/ InvestorList / GetContactList',
POSTDATA:功能(ROWID,价值,cmName){ 返回{专案编号:ROWID};
}
}
在我的ASP.NET MVC的控制器,我有以下方式:
公共JsonResult GetContactList(字符串专案编号)
{
VAR接触=新的解释和LT;字符串,字符串&GT;(); // context.GetContactList(专案编号);
contacts.Add(123,IAM1);
contacts.Add(1234,IAM2);
contacts.Add(12345,IAM3);
返回JSON(联系人,JsonRequestBehavior.AllowGet);
}
使用IE浏览器的开发者工具,这是响应:
{123:IAM1,1234:IAM2,12345:IAM3}
不过,我得到以下错误,
I'm wondering what kind of format does dataUrl
expect because I use the exact same format for other columns e.g. editoptions: { value: TeaserStatusList }
In this case TeaserStatusList
has the same format as {"123":"IAM1","1234":"IAM2","12345":"IAM3"}
Thanks
Update:
{ name: 'ContactId', editable: true, width: 100, sortable: false, edittype: 'select', editoptions: { dataUrl: '/InvestorList/GetContactList',
postData: function (rowid, value, cmName) {
var accid = $(gridId).jqGrid("getCell", rowid, "AccountId");
return { accountId: accid };
},
buildSelect: function (data) {
var s = "<select>";
data = JSON.parse(data);
$.each(data, function (k, v) {
s += '<option value="' + k + '">' + v + '</option>';
});
return s + "</select>";
}
}
jqGrid expect that dataUrl
returns HTML fragment with <select>
statement. Thus you should add buildSelect
property in editoptions
which converts the server response to the string with <select>
statement. The corresponding code could be something like below
buildSelect: function (data) {
var s = "<select>", i, l, val;
if (data != null) {
for (val in data) {
if (data.hasOwnProperty(val)) {
s += "<option value='" + val + "'>" + data[val] + "</option>";
}
}
}
return s + "</select>";
}
I didn't tested the code, but it seems to me it corresponds the format of data returned from GetContactList
action.
I would recommend you to add the line HttpContext.Current.Response.Cache.SetMaxAge (new TimeSpan(0));
at the begining of the action GetContactList
to be sure that you will have no problem with caching and the action GetContactList
will be called every time.
这篇关于jQuery的未确认前$在jqGrid的dataUrl方法P $ pssion错误edittype ='选择'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!