如何使用 jqGrid editoptions 值的函数创建有效的字符串?
How to create a valid string using a function for jqGrid editoptions value?
我尝试使用函数为 editoptions
值生成一个字符串。
该字符串应如下所示:'1:Active;2:Inactive;3:Pending;4:Suspended'
。
如果我尝试将此字符串作为值,则网格上的 select 可以正常工作,但是当我使用完全相同的函数生成它时,它不起作用。你能告诉我哪里出了问题吗?
jqGrid代码:
{
label:'Status',
name:'status',
editable:true,
edittype: "select",
stype:'select',
formatter:'select',
editoptions: { value: generate}
}
和函数
function generate(){
var s="";
$.ajax({
type:"GET",
url:"rst/crud/selectStatus",
dataType: "json",
contentType: "application/json",
success: function (data) {
response = $.parseJSON(JSON.stringify(data));
$.each(response, function(i, item) {
s+=response[i].id+":"+response[i].status+";";
});
s = s.substring(0, s.length-1);
// alert(s);
}
});
return s;
}
您当前使用的$.ajax
调用将异步执行。在 dataUrl
和 buildSelect
的情况下,您应该使用 editoptions
的 另一个特征 。问题只是该功能适用于编辑网格,但不适用于您使用的 formatter:'select'
。格式化程序将用于填充网格(用于处理服务器响应)。
我在the answer中描述了这种情况的解决方案。只需使用通过 "rst/crud/selectStatus"
提供的数据扩展服务器(主要 url
)的标准响应。您可以处理 beforeProcessing
内部的数据并使用 setColProp
修改 editoptions.value
动态 。顺便说一下,您可以根据网格列中的 真实 数据设置 value
事件。如果您使用 loadonce: true
场景,该场景特别实用。我的意思是:您可以将值集从 '1:Active;2:Inactive;3:Pending;4:Suspended'
减少到 真正使用的值 列中的某些值。这样的值对于 searchoptions.value
非常实用,但您仍然可以使用 editoptions.value
.
的全套允许值
我尝试使用函数为 editoptions
值生成一个字符串。
该字符串应如下所示:'1:Active;2:Inactive;3:Pending;4:Suspended'
。
如果我尝试将此字符串作为值,则网格上的 select 可以正常工作,但是当我使用完全相同的函数生成它时,它不起作用。你能告诉我哪里出了问题吗?
jqGrid代码:
{
label:'Status',
name:'status',
editable:true,
edittype: "select",
stype:'select',
formatter:'select',
editoptions: { value: generate}
}
和函数
function generate(){
var s="";
$.ajax({
type:"GET",
url:"rst/crud/selectStatus",
dataType: "json",
contentType: "application/json",
success: function (data) {
response = $.parseJSON(JSON.stringify(data));
$.each(response, function(i, item) {
s+=response[i].id+":"+response[i].status+";";
});
s = s.substring(0, s.length-1);
// alert(s);
}
});
return s;
}
您当前使用的$.ajax
调用将异步执行。在 dataUrl
和 buildSelect
的情况下,您应该使用 editoptions
的 另一个特征 。问题只是该功能适用于编辑网格,但不适用于您使用的 formatter:'select'
。格式化程序将用于填充网格(用于处理服务器响应)。
我在the answer中描述了这种情况的解决方案。只需使用通过 "rst/crud/selectStatus"
提供的数据扩展服务器(主要 url
)的标准响应。您可以处理 beforeProcessing
内部的数据并使用 setColProp
修改 editoptions.value
动态 。顺便说一下,您可以根据网格列中的 真实 数据设置 value
事件。如果您使用 loadonce: true
场景,该场景特别实用。我的意思是:您可以将值集从 '1:Active;2:Inactive;3:Pending;4:Suspended'
减少到 真正使用的值 列中的某些值。这样的值对于 searchoptions.value
非常实用,但您仍然可以使用 editoptions.value
.