开发者

Destroying a multiple dialog box

Hii,

I have a problem in using dialog box in开发者_StackOverflow中文版 jquery.At a point of time an event may trigger that displays a dialog box,before this dialog box closes, another event may trigger which displays a new dialog box.

Till now I am closing the dialog box explicitly before another dialog box opens by using destroy for each id.

   if($('#'+errorId).dialog("isOpen"))
                $('#'+errorId).dialog("destroy");
if($('#'+successId).dialog("isOpen"))
            $('#'+successId).dialog("destroy");

What I need is to close all dialog boxes at one go instead of one at a time.

Is this kind of solution possible?if Yes please let me know.

Thanks in Advance.

With Regards

Phani Kumar


Put a class X say 'dialog' on each of the containers opened as a dialog and then call $('.dialog').dialog('close')


One quick solution would be to store the jQuery-Object references in an array as global variable. For instance:

globalarray = new Array();
var jDialog = jQuery('selector').dialog({
   parameters: go here
});    
globalarray.push(jDialog);

With that approach, you'd have presentation and logic seperated and you could simply iterate over the array with the following:

function destroy_all_dialogs() {
   var max_length = i.length
   for (var i=0; i<max_length; ++i) {
      var jDialog = globalarray[i];
      jDialog.dialog('destroy');
   }
}

Notice that this is a simplistic solution. If you want to be more specific (maybe close only dialogs of a specific context), you'd need a more complex object to manage that. Also, I split everything up into variables for better understanding of every single step, but you can group some statements together if there are too many variables for you ;)

NOTE

If your trigger is set up in a way that it always triggers before closing, you have to remove the trigger before closing. You can add that to the destroy_all_dialogs function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜