【问题标题】:Concurrent call to a simplemodal object并发调用 simplemodal 对象
【发布时间】:2011-02-04 09:05:42
【问题描述】:

我必须让一个函数同时处理多个打开/关闭模式请求。

例如:当我调用 showAjaxLoading(true) 时,它正在显示模态,而 showAjaxLoading(false) 它正在处理模态。

问题:当我发出第一个长请求以显示模式时,另一个快速请求将关闭它。我希望能够将所有请求保存在一个数组中,并仅在最后一个请求结束时才处理模式。

SimpleModal:对象 simplemodal 是唯一的。当您创建模式时,它会返回对象本身。但是当你已经打开了一个模式时,它会返回 false。网址:http://www.ericmmartin.com/projects/simplemodal/

var showAjaxLoading = function (show) {
    var ajaxModal;
    if (show) {
        var aModal = $("#ajaxLoading").modal({ overlayId: 'ajaxloading-overlay', containerId: 'ajaxloading-container', closeClass: 'ajaxloading-close', close: false, escClose: false });
        if (aModal !== false) {
            ajaxModal = aModal;
        };
    } else {
        if (ajaxModal !== undefined && $.isFunction(ajaxModal.close)) {
            ajaxModal.close();
        };
    };
};

解决这个问题的最佳解决方案是什么?

【问题讨论】:

    标签: javascript jquery simplemodal


    【解决方案1】:
    var modalDialog = {
        _requestsInProcess: 0,
    
        showAjaxLoading : function()
        {
            if ( this._requestsInProcess == 0 )
            {
                // open overlay here
            }
    
            this._requestsInProcess++;
        },
    
        hideAjaxLoading : function()
        {
            this._requestsInProcess--;
            if ( this._requestsInProcess == 0 )
            {
                // hide overlay here
            }
        }
    }
    

    尝试这样的事情/现在您可以在每次发出 AJAX 请求时调用 modalDialog.showAjaxLoading() 并在每次请求完成时调用 modalDialog.hideAjaxLoading()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-30
      • 2010-09-06
      • 2013-08-16
      • 1970-01-01
      相关资源
      最近更新 更多