1

我刚刚从 jqgrid 3.6.5 移动到网格的 4.4.4 版本。问题是我的选择列表没有填充 dataUrl 选项和 edittype 选择。请看下图 在此处输入图像描述
从图中可以看到,grid 已经向 GetManager 和 GetTerritory 发送了两个 ajax 请求,但是结果数据没有显示在选择列表中。我添加了语言文件 jqgrid.min.js 和 grid.formedit.js。以下是其中一种列模型的代码

{ name: 'ManagerId',
                            //sortable: true,
                            index: 'ManagerId',
                            //width: 50,
                            hidden:true,
                            align: 'center',
                            formatter: 'mail',
                            editable: true,
                            edittype: 'select',
                            editoptions: {aysnc:false, dataUrl: '@Url.Action("GetManagers", "Employee")',
                                buildSelect: function (data) {
                                    var response = jQuery.parseJSON(data.responseText);

                                    var s = '<select>';
                                    s += '<option value="0">--No Manager--</option>';
                                    $($.parseJSON(data.responseText)).map(function () {


                                        s += '<option value="' + this.EmployeeId + '">' + this.EmployeeName + '</option>';
                                    });

                                    return s + "</select>";
                                }
                            },
                            editrules: { required: true,edithidden:true },
                            formoptions: { elmsuffix: ' *',label:'Manager' }
                        },

任何人都可以建议它有什么问题。

编辑 1 个
服务器响应

[{"EmployeeId":2,"EmployeeName":"Jack"},{"EmployeeId":4,"EmployeeName":"xe"},{"EmployeeId":1001,"EmployeeName":"John"},{"EmployeeId":2000,"EmployeeName":"Jack"},{"EmployeeId":2001,"EmployeeName":"Jill"}]

响应标头

Cache-Control   private
Connection  Close
Content-Length  203
Content-Type    application/json; charset=utf-8
Date    Thu, 14 Feb 2013 13:20:09 GMT
Server  ASP.NET Development Server/10.0.0.0
X-AspNet-Version    4.0.30319
X-AspNetMvc-Version 3.0

谢谢

4

1 回答 1

2

首先,我建议您检查回调data内部的参数类型。buildSelect取决于其他一些因素,data可能已经是从 JSON 响应中解析的对象。你可以只包括alert(typeof data.responseText);在开头buildSelect。或者,您可以使用jQuery.isArray来验证data参数是否已经是数据数组或需要使用jQuery.parseJSON将输入数据转换为数组。

下一个问题是您使用jQuery.map而不是jQuery.each。所以代码可能是关于以下内容

buildSelect: function (response) {
    var data = typeof response === "string" ?
                   $.parseJSON(response.responseText) : response,
        s = "<select>";

    s += '<option value="0">--No Manager--</option>';
    $.each(data, function () {
        s += '<option value="' + this.EmployeeId + '">' + this.EmployeeName +
           '</option>';
    }
    return s + "</select>";
}

您应该另外修复aysnc:false. editoptions这些选项是未知的,将被忽略。

于 2013-02-14T14:03:32.693 回答