提交后关闭添加对话框

Close add dialog after submit

我用的是jqgrid 4.6.0

  • @license jqGrid 4.6.0 - jQuery Grid
  • Copyright (c) 2008, Tony Tomov, tony@trirand.com

问题是我添加新记录后,对话框没有关闭。

$(gridSelector).jqGrid('navGrid', pagerSelector,
                {
                    //navbar options
                    edit: true,
                    editicon: 'ace-icon fa fa-pencil blue',
                    add: true,
                    addicon: 'ace-icon fa fa-plus-circle purple',
                    del: true,
                    delicon: 'ace-icon fa fa-trash-o red',
                    search: true,
                    searchicon: 'ace-icon fa fa-search orange',
                    refresh: true,
                    refreshicon: 'ace-icon fa fa-refresh green',
                    view: true,
                    viewicon: 'ace-icon fa fa-search-plus grey'
                },
                {
                    //edit record form
                    //closeAfterEdit: true,
                    //width: 700,
                    recreateForm: true,
                    mtype: 'PUT',
                    onclickSubmit: function (params, postdata) {
                        params.url = API_URL;
                    },
                    beforeShowForm: function (e) {
                        var form = $(e[0]);
                        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />');
                        styleEditForm(form);
                    }
                },
                {
                    //new record form
                    //width: 700,
                    closeAfterAdd: true,
                    recreateForm: true,
                    viewPagerButtons: false,
                    mtype: 'POST',
                    onclickSubmit: function (params, postdata) {
                        params.url = API_URL + 'PostVendor';
                    },
                    afterSubmit: function (response, postdata) {
                        var userKey = JSON.parse(response.responseText).UserKey;
                        alert("The password you created for the new vendor is\n\n" + userKey);
                    },
                    beforeShowForm: function (e) {
                        var form = $(e[0]);
                        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
                            .wrapInner('<div class="widget-header" />');
                        styleEditForm(form);
                    }
                }

但是我在 POST 部分有 closeAfterAdd: true

你的问题原因很简单,但是很难定位。您包含了 afterSubmit,您以错误的方式实现了它。回调函数必须 return 数组至少有一个元素。通常回调 returns

[true]

这意味着 jqGrid 应该将服务器响应解释为成功。如果对服务器响应内容的分析表明服务器端对请求的处理失败,则回调 afterSubmit 应该 return 结果类似于

[false, "It's <em>Important</em> error on the server side!!!"]

您的代码 return undefined 我想您会在调用 afterSubmit 回调后处理下一条语句时看到异常,因为 res[0] 将与undefined 变量 res.