【问题标题】:jqGrid Select not updating onchange (C# MVC)jqGrid Select 不更新 onchange (C# MVC)
【发布时间】:2018-02-18 23:01:26
【问题描述】:

我通过 dataInit 中的 ajax 调用加载数据,它工作正常,一切正常,但我的所有列(仅下拉列)都没有设置 id 值。

例如我有 itemId 和 itemCode 属性。我加载数据并正确显示,但如果我更改下拉列表中的值,则它不会绑定/更新我的 itemId 值。

基本上我希望下拉列表绑定到我的 id 列,因此在保存它时我会得到一个要保存的 ID。

,{
                    key: false,
                    hidden: true,
                    name: 'itemId',
                    index: 'itemId',
                    editable: false
                }, {
                    key: false,
                    name: 'itemCode',
                    index: 'itemId',
                    editable: true,
                    edittype: 'select',
                    editoptions: {
                        dataInit: function(element) {
                            $.ajax({
                                url: '@Url.Action("GetItems", "Maintenance")',
                                dataType: 'json',
                                type: 'POST',
                                success: function(response) {
                                    var array = response;
                                    if (array != null) {
                                        var i;
                                        for (i in array) {
                                            if (array.hasOwnProperty(i)) {
                                                if (itemId == array[i].id) {
                                                    $(element).append("<option value=" +
                                                        array[i].id +
                                                        " selected>" +
                                                        array[i].code +
                                                        "</option>");
                                                } else {
                                                    $(element).append("<option value=" +
                                                        array[i].id +
                                                        ">" +
                                                        array[i].code +
                                                        "</option>");
                                                }
                                            }
                                        }
                                    }
                                }
                            });
                        }
                    },
                    editrules: { required: true}

【问题讨论】:

    标签: javascript c# jquery asp.net-mvc jqgrid


    【解决方案1】:

    这是我的答案.....看看数据事件。我找到选定的行,然后设置单元格。控制台日志只是为了测试。

    {
                        key: false,
                        hidden: true,
                        name: 'userId',
                        index: 'userId',
                        editable: false
                    }, {
                        key: false,
                        name: 'userName',
                        index: 'userName',
                        editable: true,
                        edittype: 'select',
                        editoptions: {
                            dataInit: function(element) {
                                $.ajax({
                                    url: '@Url.Action("GetUsers", "Maintenance")',
                                    dataType: 'json',
                                    type: 'POST',
                                    success: function(response) {
                                        var array = response;
                                        if (array != null) {
                                            var i;
                                            for (i in array) {
                                                if (array.hasOwnProperty(i)) {
                                                    if (userId == array[i].id) {
                                                        $(element).append("<option value=" +
                                                            array[i].id +
                                                            " selected>" +
                                                            array[i].userName +
                                                            "</option>");
                                                    } else {
                                                        $(element).append("<option value=" +
                                                            array[i].id +
                                                            ">" +
                                                            array[i].userName +
                                                            "</option>");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                });
                            },
                            dataEvents: [
                                {  type: 'change',
                                    fn: function (e) {
                                        var rowId = $("#jqgrid").jqGrid('getGridParam', 'selrow');
                                        $('#jqgrid').jqGrid('setCell', rowId, 'userId', $(e.target).val());
                                        console.log($("#jqgrid").jqGrid('getCell', rowId, 'userId'));
                                    }
                                }
                            ]
                        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多