如何在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">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</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');
如果你想以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}}