Jquery easyUI dialog的close和destroy

来源:互联网 发布:ai作图软件 编辑:程序博客网 时间:2024/06/04 17:57

之前在用easyUI的时候遇到一个问题,一直困扰着我。

问题:

使用dialog来实现保存和编辑框,使用dialog.(“close”)来关闭dialog框,这个时候如果有两个页面的保存页面的表单的字段相同时,这两个表单的东西就会混乱。要不就是保存时打不开,要不就是编辑页面打开数据初始化不了。

解决思路:

使用close的方法来关闭dialog时,此dialog并不是完全消失,只是隐藏起来了而已。当另外一个dialog和这个dialog相同时,就会发生混乱。所以我们不适用close的方法来关闭dialog,使用destroy来销毁dialog,当使用destroy时,如果页面上显式定义了dialog的话,关闭后就永远都打不开了。所以我们不显式定义dialog,并且把保存页面和列表页面分开。

解决代码如下:
list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ page import="com.ourpalm.resupgrade.bean.GmMenu"%><%@ page import="com.ourpalm.resupgrade.bean.GmModule"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><%    String path = request.getContextPath();    request.setAttribute("path", path);    String basePath = request.getScheme() + "://"            + request.getServerName() + ":" + request.getServerPort()            + path + "/";%><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title><fmt:message key="resourceUploadGM" /></title><link rel="stylesheet" type="text/css"    href="<%=path%>/themes/default/easyui.css"><link rel="stylesheet" type="text/css" href="<%=path%>/themes/icon.css"><script type="text/javascript" src="<%=path%>/js/jquery-1.8.0.min.js"></script><script type="text/javascript" src="<%=path%>/js/jquery.easyui.min.js"></script><fmt:setLocale value="${local}" /><fmt:setBundle basename="applicationMessage" /></head><body>    <table id="dgResource" class="easyui-datagrid" fit="true" url=""        toolbar="#toolbar" pagination="true" rownumbers="true"        fitColumns="true" singleSelect="true" pageSize="15"        pageList="[15,20,25,30,35]">        <thead>            <tr>                <th data-options="field:'id',width:20,align:'center'">id</th>                <th data-options="field:'resourcePath',width:40,align:'center'"><fmt:message                        key="resourceFileName" /></th>            </tr>        </thead>        <tr></tr>    </table>    <div id="toolbar" style="padding: 5px; height: auto">        <div style="margin-bottom: 5px">            <a href="javascript:void(0)" class="easyui-linkbutton"                iconCls="icon-add" plain="true" onclick="newResource()"><fmt:message                    key="add" /></a> <a href="javascript:void(0)"                class="easyui-linkbutton" iconCls="icon-edit" plain="true"                onclick="editResource()"><fmt:message key="edit" /></a> <a                href="javascript:void(0)" class="easyui-linkbutton"                iconCls="icon-remove" plain="true" onclick="destroyResource()"><fmt:message                    key="delete" /></a> <a href="javascript:void(0)"                class="easyui-linkbutton" iconCls="icon-remove" plain="true"                onclick="UpdateResourceBeansProduced()"><fmt:message                    key="flushcatch" /></a>        </div>    </div>    <script type="text/javascript">        $("#dgResource").datagrid({            url : "${path}/resourceServlet.do?method=search&fromFlg=lodad"        });        function editResource() {            var row = $('#dgResource').datagrid('getSelected');            if (row) {                $('<div></div>').dialog({                    id : 'newDialog',                    title : 'My Dialog',                    width : 800,                    height : 600,                    closed : false,                    cache : false,                    href : '${path}/view/gmtool/resource_save.jsp',                    modal : true,                    onLoad : function() {                        //初始化表单数据                    },                    onClose : function() {                        $(this).dialog('destroy');                    },                    buttons : [ {                        text : 'OK',                        iconCls : 'icon-ok',                        handler : function() {                            //提交表单                        }                    }, {                        text : 'CANCEL',                        iconCls : 'icon-cancel',                        handler : function() {                            $("#newDialog").dialog('destroy');                        }                    } ],                });            }        }    </script></body></html>

save.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ page import="com.ourpalm.resupgrade.bean.GmMenu"%><%@ page import="com.ourpalm.resupgrade.bean.GmModule"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><%    String path = request.getContextPath();    request.setAttribute("path", path);    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title><fmt:message key="resourceUploadGM" /></title><link rel="stylesheet" type="text/css" href="<%=path%>/themes/default/easyui.css"><link rel="stylesheet" type="text/css" href="<%=path%>/themes/icon.css"><script type="text/javascript" src="<%=path%>/js/jquery-1.8.0.min.js"></script><script type="text/javascript" src="<%=path%>/js/jquery.easyui.min.js"></script><fmt:setLocale value="${local}" /><fmt:setBundle basename="applicationMessage" /></head><body>    <div class="ftitle">        <fmt:message key="resourceinformation" />    </div>    <form id="fmResource" method="post" novalidate>        <div style="display: none;">            <input name="id" id="id" value="">        </div>        <div class="fitem">            <label class="rightalign"><fmt:message key="resourceFileName" />:</label>            <input name="resourcePath" id="resourcePath"                class="easyui-validatebox" required="true">        </div>    </form>    <script type="text/javascript">    </script></body></html>
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 摩托车购车发票写了别人名字怎么办 新领的发票跟电脑对不上号怎么办 淘宝未发货退款卖家拒绝怎么办 在超市买东西把票丢了不让出怎么办 在淘宝上买东西付款不发货怎么办 买家拍下商品卖家拒绝发货怎么办 没有中文标签被投诉到工商局怎么办 淘宝申请退款卖家强制发货怎么办 1688卖家交易不小心关闭怎么办 拼多多两天不发货怎么办自动退款吗 在家里放的东西找不到了怎么办 在家里烧东西烟太大了怎么办 转转上买的二手东西有问题怎么办? 大巴车过虎门大桥错走小车道怎么办 pe高压膜中间松两边紧怎么办? 穿着浅口的高跟鞋走路老是掉怎么办 五吧同城模特兼职被骗了怎么办 华为手机充电玩黑屏怎么办教学视频 衣服肩膀被衣架撑变形了怎么办 货已经安到客户家客户不付款怎么办 微商卖家不给退货不给换货怎么办啊 淘宝卖家已签收退货却不退款怎么办 申请换货卖家收到货不给换怎么办 我买了个机器想退货怎么办 卖家要求退回去又拒收怎么办 拼多多48小时还不发货怎么办 退货退款单号填错了退不了款怎么办 淘宝退货退款快递单号填写错怎么办 蘑菇街退货忘记填快递单号了怎么办 您尝试购买的项目已停止供货怎么办 oppo新手机搬家搬了一半怎么办 开手机店手机卖不出去怎么办 京东买的东西误按签收了怎么办 小米5x充电宝充电自动断电怎么办 小米2s开不了机怎么办充电闪红灯 寄快递写错地址但已经发货了怎么办 拼多多发货时快递公司写错了怎么办 千牛发货信息写错了怎么办 发货物流单电话写错了怎么办 顺丰寄电脑保价后电脑进水了怎么办 微销通分享小程序没有二维码怎么办