简体   繁体   English

自举动态模态

[英]Bootstrap Dynamic Modal

I've been trying to do the dynamic modal with the twitter bootstrap like so: 我一直在尝试使用twitter引导程序执行动态模态,如下所示:

$('#myModal').on('hide', function () { 
    $(this).removeData('modal');
    $('.loading-modal').remove();
})

It does reload the data in the modal each time I click on the button but... 每次我单击按钮时,它都会在模态中重新加载数据,但是...

What I noticed is that after closing the previews modal, when I open the next modal the previews data is still shown and after a few seconds it is updated with the new data. 我注意到的是,在关闭预览模式后,当我打开下一个模式时,仍然显示预览数据,并在几秒钟后使用新数据进行更新。

What I wanted is that everytime the modal is called it will set the data to "Loading..." then display the new data. 我想要的是每次调用模态时都会将数据设置为“正在加载...”,然后显示新数据。

How can this be achieved? 如何做到这一点? Or is there a better approach? 还是有更好的方法?


Update 更新

This is how I'm calling the remote data for the modal using data-remove= 这就是我使用data-remove=调用模式的远程数据的方式

<a href="" role="button" data-target="#myModal" data-toggle="modal" data-backdrop="static" data-remote="/manager/test/{{ $donator->USERNO }}"><i class="icon-plus"></i></a>

The modal 模态

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Editing Data</h3>
    </div>
    <div class="modal-body">
        <div class="loading-modal">Loading...</div>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
    </div>
</div>

I have done a similar thing using Ajax, not sure if it is 'the best' way to do it, but it works. 我使用Ajax做过类似的事情,不确定这是否是“最佳”方法,但是它可以工作。

Just use a normal button/hyperlink with a Javascript function call: 只需将常规按钮/超链接与Javascript函数调用配合使用即可:

<button class="btn" onclick="showDialog()">Click Me</button>

And then inside the function show the dialog and perform ajax call: 然后在函数内部显示对话框并执行ajax调用:

function showDialog() {
    $("#dialogBody").html("Loading...");  // Or use a progress bar...
    $("#dialog").modal("show");
    $.ajax({
        url: myUrl.com,
    }).success(function(data) {
        $("#dialogBody").html(data);
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM