Twitter bootstrap remote modal shows same content every time

前端 未结 22 1382
春和景丽
春和景丽 2020-11-22 12:29

I am using Twitter bootstrap, I have specified a modal

<
22条回答
  •  醉话见心
    2020-11-22 13:17

    Expanded version of accepted answer by @merv. It also checks if modal being hidden is loaded from remote source and clears old content to prevent it from flashing.

    $(document).on('hidden.bs.modal', '.modal', function () {
      var modalData = $(this).data('bs.modal');
    
      // Destroy modal if has remote source – don't want to destroy modals with static content.
      if (modalData && modalData.options.remote) {
        // Destroy component. Next time new component is created and loads fresh content
        $(this).removeData('bs.modal');
        // Also clear loaded content, otherwise it would flash before new one is loaded.
        $(this).find(".modal-content").empty();
      }
    });
    

    https://gist.github.com/WojtekKruszewski/ae86d7fb59879715ae1e6dd623f743c5

提交回复
热议问题