【问题标题】:Close add dialog after submit提交后关闭添加对话框
【发布时间】:2016-01-21 14:12:42
【问题描述】:

我使用 jqrrid 4.6.0

  • @license jqGrid 4.6.0 - jQuery 网格
  • 版权所有 (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

【问题讨论】:

  • 顺便说一下,我在free jqGrid的代码中做了the changes,以防止afterSubmitbeforeSubmit不返回任何数据时出现异常。

标签: jquery jqgrid


【解决方案1】:

您的问题的原因很容易,但很难找到。你包括了afterSubmit,你以错误的方式实现了它。回调函数必须返回包含至少一个元素的数组。通常回调返回

[true]

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

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

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

【讨论】:

  • 感谢您一直以来的帮助。很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多