使用表单编辑时的jqgrid多选下拉列表

这是我的multiselect下拉列的代码。 它按预期工作,但我想在编辑模式上进行一些修改。

{ 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 = '', i; response = jQuery.parseJSON(data); // s += '--Select Subject--'; if (response && response.length) { $.each(response, function (i) { s += '' + this.SubjectName + ''; }); } return s + ''; }, dataInit: function (elem) { setTimeout(function () { $('#SubjectId').multiselect(); }, 5); }, multiple: true, } }, 

但是在编辑模式下,我想让多选错误。怎么做。我不明白怎么做。

首先你的代码有输入错误:一个应该使用dataInit而不是ddataInit

如果你只需要在Add表单中而不是在Edit表单中使用dataInit我建议你最好不要使用dataInit multiselect: truedataInit 。 而不是你可以使用beforeShowForm回调(参见文档 )。 在回调内部,您可以设置multiple属性(请参阅jQuery.attr )并调用$('#SubjectId').multiselect(); 。 如果只为Add表单指定这样的beforeShowForm回调,则应该具有所需的行为。 对于添加和编辑表单,您应该使用recreateForm: true 属性 。