删除对话框不会删除其内部内容 [英] remove a dialog is not removing its inner contents

查看:86
本文介绍了删除对话框不会删除其内部内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个对话框,并在该对话框中创建了一个UI选项卡.在该选项卡中,我将一些内容显示为表格.当我通过remove()方法关闭对话框时,它关闭了对话框,但是当我重新打开对话框时,内容仍显示在选项卡中,是否有任何方法在对话框关闭时也能删除内容.下面是我的代码.

I have made a dialog and a UI Tab in that dialog. In that tab i am showing some contents as a table. When i close the dialog by remove() method it closes the dialog but when i reopen it the contents are still showing in the tab, is there any method that contents will also reomve when dialog closes. below is my code.

this.formOrderList = null;
this.orderListDialogObject = $('<div id="mainDiv"></div>');
this.orderListTable = $('<div>'
        + '<table class="ui-widget" width="100%" border="0"  cellspacing="1" cellpadding="2">'
        + '<thead class="ui-widget-header" id="orderListHead">' + '<tr>'
        + '<th><strong> Order# </strong></th>'      
        + '<th><strong> Ref # </strong></th>' + '</tr>' + '</thead>'
        + '<tbody id="orderListBody">' + '</tbody>' + '</table>' + '</div>');
this.orderListTabs = $('<div>' + '<ul>'
        + '<li><a href="#pendingOrderList">Pending</a></li>' + '</ul>'
        + '<div id="pendingOrderList">' + '</div>' + '</div>');

this.show = function() {
    this.orderListDialogObject.dialog({
        title : 'Order List',
        width : 1000,
        height : 150,
        close : function(ev, ui) {              
    $(this).remove();               
            return false;
        }
    });
this.orderListTabs.tabs();
    this.orderListTabs.appendTo(this.orderListDialogObject);        
    $("#pendingOrderList", this.orderListTabs).append(this.orderListTable);

推荐答案

您一次创建了div,然后重复使用了相同的实例.您的 remove 调用只会从DOM树中删除该div(及其所有内容)- -您没有做任何会清除div内容的操作.

You're creating your divs once, and then reusing those same instances repeatedly. Your remove call just removes that div (along with all of its contents) from the DOM tree -- you're not doing anything that will clear the div's contents.

您可能应该:

  1. 每次显示对话框时都要创建一组新的div,例如,每次要显示对话框时,重新运行上述所有代码每个,而不是一次执行其中的一些前期.这样,您每次都会从头开始.或者,
  2. 在开始向其中添加新内容之前,请调用 .
  1. Create a new set of divs each time you show the dialog -- i.e., re-run all of the above code each time you want to show the dialog, rather than doing some of it once up-front. That way, you're starting with a clean slate each time. Or,
  2. Clear the contents of one or more of the divs before you start adding new stuff to it, by calling empty().

在大多数情况下,选项#1可能更清洁并且更易于维护.

Option #1 would probably be cleaner and easier to maintain in most cases.

这篇关于删除对话框不会删除其内部内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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