在 EasyUI 中,若需要開啟第二層彈出式視窗,可以自行封裝一個 dialog 方法。重點是透過 handler 保留目前彈窗實例,避免重複開啟,並在關閉時清理資源。
$.modalDialogTwo = function(options) {
if ($.modalDialogTwo.handler == undefined) {
var opts = $.extend({
title: '',
width: 840,
height: 680,
modal: true,
onClose: function() {
$.modalDialogTwo.handler = undefined;
$(this).dialog('destroy');
}
}, options);
opts.modal = true;
return $.modalDialogTwo.handler = $('<div/>').dialog(opts);
}
};這樣設計後,呼叫端只要決定標題、寬高與內容,就能快速開啟第二層視窗;關閉後也會自動釋放,不會殘留舊的 dialog 物件。