无法销毁引导模式数据

Cannot destroy bootstrap modal data

本文关键字:模式 数据      更新时间:2023-09-26
  • j查询 1.11.2
  • 引导程序 3.1.1

以下是我构建模态的方式:

    function fillModal(url, callback) {
        $(document).on('shown.bs.modal', '#modal', function(){
            $('#modal').find('.modal-content').load(url, function() {
                callback();
            });
        });
    }

这是我试图摧毁它的方式。

   $(document).on('hidden.bs.modal', '#modal', function (e) {
        $('#modal').find('.modal-content').empty();
        $(this).find('.modal-content').empty();
        $(e.target).find('.modal-content').empty();
        $('#modal').data('modal', null);
        $('#modal').data('bs.modal', null);
        $('#modal').removeData('bs.modal');
        $('#modal').removeData('modal');
        $(this).data('bs.modal', null);
        $(this).data('modal', null);
        $(this).removeData('bs.modal');
        $(this).removeData('modal');
        $(e.target).data('modal', null);
        $(e.target).data('bs.modal', null);
        $(e.target).removeData('bs.modal');
        $(e.target).removeData('modal');
    });

上面的调用触发,我已经尝试了一切方法来实际吹走引导缓存数据,但它根本不起作用。我已经单独尝试了其中的每一个,我一起尝试过,我尝试破坏整个模态 HTML 并重新添加它。

没有任何效果 - 模态的内容总是由两个或三个请求旧,有时内容会恢复为非常旧的请求。有时他们会是正确的。有时它们会在一瞬间正确,然后被缓存的数据覆盖......

我不知道出了什么问题。

构建模态时,是否有我可以应用的设置,例如"dontKeep"或"noCache"之类的设置?

显然,当您调用 shown.bs.modal 时,它会在每次调用时将您的回调附加到堆栈中,而不是替换那里的内容。所以我第一次点击时,它添加了回调。第二次单击时,它会在第一个回调后附加一个新的回调,第三次单击时,它会附加第三个回调,依此类推......

然后,这些回调按照它们碰巧完成的顺序呈现内容,这就是为什么内容看起来可以随机出现的原因。

我通过简单地不将填充行为的模态内容附加到 shown.bs.modal 事件,而只是在单击后立即调用它来解决此问题。