提交后关闭添加对话框 [英] Close add dialog after submit

查看:169
本文介绍了提交后关闭添加对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jqrrid 4.6.0

I use jqrrid 4.6.0

  • @license jqGrid 4.6.0-jQuery网格
  • 版权所有(c)2008,Tony Tomov,tony @ trirand.com
  • @license jqGrid 4.6.0 - jQuery Grid
  • Copyright (c) 2008, Tony Tomov, tony@trirand.com

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

The thing is after I add new record, the dialog is not closed.

$(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,但您以错误的方式实现了该代码.回调函数必须返回至少包含一个元素的数组.通常,回调会返回

The reason of your problem is very easy, but it's difficult to locate. You included afterSubmit, which you implemented in the wrong way. The callback function have to return array with at least one element. Typically the callback returns

[true]

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

which means that jqGrid should interpret the server response as successful. If analyzing of the content of the server responds shows that the server side processing of the request failed then the callback afterSubmit should return the result like

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

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

Your code return undefined and I suppose that you will see an exception in processing the next statement after calling afterSubmit callback, because res[0] will be used with undefined variable res.

这篇关于提交后关闭添加对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆