Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用表单编辑时的jqgrid multiselect下拉列表_Jquery_Jqgrid - Fatal编程技术网

Jquery 使用表单编辑时的jqgrid multiselect下拉列表

Jquery 使用表单编辑时的jqgrid multiselect下拉列表,jquery,jqgrid,Jquery,Jqgrid,这是我的多选下拉栏的代码。它的工作正如我所期望的,但我想对编辑模式进行一些修改 { name: 'SubjectId', index: 'SubjectId', align: 'center', hidden: true, viewable: true, editrules: { edithidden: true }, editable: true, formatter: 'select', editable: true,

这是我的多选下拉栏的代码。它的工作正如我所期望的,但我想对编辑模式进行一些修改

{
    name: 'SubjectId',
    index: 'SubjectId',
    align: 'center',
    hidden: true,
    viewable: true,
    editrules: { edithidden: true },
    editable: true,
    formatter: 'select',
    editable: true,
    edittype: 'select',
    editoptions: {
        multiselect: true,
        dataUrl: '@Url.Action("getAllSubjects", "Subject")',
        //buildSelect: function (data) {
        //var retValue = $.parseJSON(data);
        buildSelect: function (data) {
            var response, s = '<select>', i;
            response = jQuery.parseJSON(data);
            // s += '<option value="0">--Select Subject--</option>';
            if (response && response.length) {
                $.each(response, function (i) {
                    s += '<option value="' + this.Id + '">' + this.SubjectName + '</option>';
                });
            }
            return s + '</select>';
        },

        dataInit: function (elem) {
            setTimeout(function () {
                $('#SubjectId').multiselect();
            }, 5);

        },
        multiple: true,
    }
},
{
名称:“主语”,
索引:“主语”,
对齐:'居中',
隐藏:是的,
可见:对,
editrules:{edithidden:true},
是的,
格式化程序:“选择”,
是的,
edittype:'选择',
编辑选项:{
多选:对,
dataUrl:'@Url.Action(“getAllSubjects”,“Subject”),
//buildSelect:函数(数据){
//var retValue=$.parseJSON(数据);
buildSelect:函数(数据){
var响应,s='',i;
response=jQuery.parseJSON(数据);
//s+='--选择主题--';
if(响应和响应长度){
$。每个(响应、功能(i){
s+=''+this.SubjectName+'';
});
}
返回s+“”;
},
dataInit:函数(elem){
setTimeout(函数(){
$('#subject').multiselect();
}, 5);
},
多重:对,
}
},

但在编辑模式下,我想将multiselect设为false。我怎么能做到。我不知道怎么做。

首先,您的代码有键入错误:应该使用
dataInit
而不是
ddatanit


如果您只需要在添加表单中而不在编辑表单中使用
multiselect
,我建议您最好不要使用
multiselect:true
dataInit
。相反,您可以使用
beforeShowForm
回调(请参阅)。在回调中,您可以设置
multiple
属性(请参阅)并调用
$(“#SubjectId”).multiselect();
。如果只为添加表单指定
之前的showForm
回调,则应该具有所需的行为。在这种情况下,您应该对添加和编辑表单都使用
recreateForm:true

在下面我使用的添加选项中,但没有按预期工作{recreateForm:true,closeOnEscape:true,reloadeAfterSubmit:true,closeAfterAdd:true,beforeShowForm:function(){$.attr($('.#SubjectId').multiselect())@janina:1)您应该设置
multiple
的属性$(“#SubjectId”).attr(“multiple”、“multiple”)。代码
$.attr($(“#SubjectId”).multiselect())
是完全错误的。2)使用
buildSelect
。因此调用
$(“#SubjectId”).multiselect();
应该在
setTimeout
的内部,并且在
显示前都在
的内部。