javascript – 在Meteor中显示/隐藏模态

如何在Meteor中显示引导模式?

http://meteorpedia.com/read/Modals我可以看到Meteor-way是使用模板逻辑来显示/隐藏模态.

我试过在我的模板中添加模态

<div class="modal fade">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          <span class="sr-only">Close</span>
        </button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

我有一个变量showModal,它确定是否应该显示模态.但我不知道如何以编程方式显示/隐藏模态.

解决方法:

在模态中添加id

<div id="myModal" class="modal fade">

并使用modal()打开模态

$('#myModal').modal('show');

关闭模态

$('#myModal').modal('hide');

Docs

如果你想以Meteor方式打开模态

在JS中

Session.set('showModal', true); // Show modal
Session.set('showModal', false); // Hide modal

在模板中

{{#if showModal}}
    <div class="modal fade"> <!-- Use Display block to show the modal by default -->
    ...

{{/if}}

相关文章

1.第一步 设置响应头 header(&#39;Access-Control-Allow...
$.inArray()方法介绍 $.inArray()函数用于在数组中搜索指定的...
jquery.serializejson.min.js的妙用 关于这个jquery.seriali...
JS 将form表单数据快速转化为object对象(json对象) jaymou...
jQuery插件之jquery.spinner数字智能增减插件 参考地址:http...