【问题标题】:Bootstrap modal doesn't appear in Meteor引导模式不会出现在 Meteor 中
【发布时间】:2013-02-17 01:21:54
【问题描述】:

我正在尝试让 Bootsrap 的模式工作,但是当我单击按钮时,我得到的只是一个黑屏,没有出现我期望的模式对话框。我正在使用流星。

这是我的代码:

<div class="container">
    <h2>Example of creating Modals with Twitter Bootstrap</h2>
    <div class="modal hide fade in" id="example" style="display: none; ">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">×</a>
            <h3>This is a Modal Heading</h3>
        </div>
        <div class="modal-body">
            <h4>Text in a modal</h4>
            <p>You can add some text here.</p>
        </div>
        <div class="modal-footer">
            <a class="btn btn-success" href="#">Call to action</a>
            <a class="btn" data-dismiss="modal" href="#">Close</a>
        </div>
    </div>
    <p><a data-toggle="modal" href="#example" class="btn btn-primary btn-large">Launch
        demo modal</a></p>
</div>

我基本上是从http://www.w3resource.com/twitter-bootstrap/modals-tutorial.php 获得代码用于测试目的。

【问题讨论】:

  • 我用引导创建了一个空白的流星项目,上面的代码工作正常。你还有其他的js插件吗
  • 嗯,我创建了一个空白项目,它也在工作。我在包文件夹中包含标准 js 插件。我还有一些其他的 js 插件,但它们与引导程序并没有真正的关系。我刚刚做了流星引导添加。
  • 也许有一些冲突?默认情况下包含 JQuery,因此您不必添加它,如果您使用流星添加它们,您的插件文件夹中也不需要它们。你具体有哪些?您能否尝试一次删除一个以查看它何时开始工作?
  • 您是否使用源代码中的整个 HTML?你的控制台有错误吗?
  • 您的模态是否包含在&lt;template&gt;&lt;/template&gt; 中?在那种特定情况下,我也有同样的问题。每当调用模态的元素嵌套在templatetags 中时,我都会看到一个空白屏幕。对此进行修复将非常有用。

标签: twitter-bootstrap modal-dialog meteor


【解决方案1】:

我遇到了同样的问题。我从模态中删除了“隐藏”类,然后它就起作用了。 我还必须将模态框与激活它的链接一起包含在同一个模板中。

代替

<div class="modal hide fade in" id="example" style="display: none; ">

试试这个

<div class="modal fade" id="example" style="display: none;">

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。问题是 Meteor 和 Bootstrap 工作方式的根本区别。 Meteor 假设可以随时重新加载标记。如果任何实时变量发生变化,Meteor 只会重新加载模板。另一方面,Bootstrap 假设模板只会被加载一次,并在运行时用 javascript 修改它们。

    正在发生的事情是流星正在加载我的模态模板。在某些时候,我正在单击某些东西,这会导致该模式出现在 javascript 中。然而,片刻之后,一个实时变量发生了变化,导致模板再次加载。由于模板隐藏了模式,它覆盖了只是试图显示模板的 javascript。

    我通过将模态框的内部放在与外部不同的模板中解决了这个问题。外部模板不响应任何实时变量,因此希望它永远不会被重新加载。

    之前:

    <template name="modal">      
      <div class="modal hide fade in" id="settings-modal" data-backdrop="false">
        <div class="modal-header">
        ...
    </template>
    

    之后:

    <template name="modal">      
      <div class="modal hide fade in" id="settings-modal" data-backdrop="false">
        {{> modalInner}}
      </div>
    </template>      
    
    <template name="modalInner">
      <div class="modal-header">
        ...
    </template>
    

    【讨论】:

    • 另请注意,为了处理关闭模式,您需要将事件处理程序放在外部模板上,而不是内部。
    • 谢谢!轻松解决了我自己的相关问题,感谢您以有用的方式解决更大的问题。
    【解决方案3】:

    我找到了一个不错的解决方案——我的 Modal 是它自己的模板,并且会话变量控制它是否显示。在它被“渲染”之后,我触发引导程序的 JS 来“打开”它。

    ...
    {{#if getSession 'isRegisterConfirmation'}}
      {{> registerConfirm}}
    {{/if}}
    </template>
    
    <template name="registerConfirm">
    <div class="modal registerConfirmModal">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>Confirm Name / Info</h3>
      </div>
      <div class="modal-body">
        You are registering as
        ...
    

    棘手的部分是在 Meteor 和 Bootstrap 之间绑定事件。

    • 在 Meteor 渲染上 -> 触发 Bootstrap 模态显示
    • 在 Bootstrap 模式下隐藏 -> 从 Meteor 中清除会话变量

    这实际上效果很好,这是我正在做的简化版本...

    Template.registerConfirm.rendered = function() {
      var thing = Session.get('thingToConfirm');
      $('.registerConfirmModal').on('hidden', function() {
        Session.set('thingToConfirm', '');
        Session.set('isRegisterConfirmation', false);
      });
      $('.registerConfirmModal').on('shown', function() {
        $('.registerConfirmModal button.confirm').focus();
      });
      $('.registerConfirmModal').modal('show');
    };
    

    然后触发模态就像将会话变量设置为true一样简单......所有其余的交换都基于事件。

    【讨论】:

      【解决方案4】:

      这是一个示例应用程序,它展示了如何使用 Meteor 显示引导模式:

      您可以在此处查看实时版本:

      【讨论】:

        猜你喜欢
        • 2021-03-08
        • 2018-07-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-08
        • 1970-01-01
        • 2017-06-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多