【问题标题】:Show/hide modal in Meteor在 Meteor 中显示/隐藏模态
【发布时间】:2015-12-21 22:36:03
【问题描述】:

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

http://meteorpedia.com/read/Modals我可以读到流星方式是使用模板逻辑来显示/隐藏模态。

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

<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,它决定是否显示模态框。但我不知道如何以编程方式显示/隐藏模式。

【问题讨论】:

    标签: javascript jquery node.js twitter-bootstrap meteor


    【解决方案1】:

    向模态框添加 id

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

    并使用modal()打开模态

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

    关闭模态

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

    Docs


    如果你想用 Meteor 方式打开 modal

    在 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}}
    

    【讨论】:

    • 但是从我发布的链接中,它说这是 jquery 方式,而不是 Meteor 方式
    • @Jamgreen Meteor 方式意味着只在Session 中存储一个变量并使用该变量来显示/隐藏模态。
    【解决方案2】:

    使用 bootstrap meteor-modal 包让自己的生活变得轻松。我用这个,效果很好meteor modal

    【讨论】:

    猜你喜欢
    • 2016-05-03
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 2015-07-16
    • 1970-01-01
    相关资源
    最近更新 更多