【问题标题】:Bootstrap 3 modal pattern with Ember.js带有 Ember.js 的 Bootstrap 3 模态模式
【发布时间】:2013-08-25 05:37:08
【问题描述】:

这是我试图建立代码的基础(基于 Bootstrap ~2):

http://jsfiddle.net/marciojunior/tK3rX/

<script type="text/x-handlebars" data-template-name="application">
    <h1>Boostrap modal sample</h1>    
    <a {{action showModal}} href="#">Open modal</a>
</script>

<script type="text/x-handlebars" data-template-name="modal">
<!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">{{view.title}}</h4>
        </div>
        <div class="modal-body">
          <p>{{view.content}}</p>
        </div>
        <div class="modal-footer">
          <button type="button" {{action close target="view"}} class="btn btn-default" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
</script>

这是我使用 Bootstrap 3 的 jsfiddle:

http://jsfiddle.net/5R8U9/9/

谁能帮我找出我的小提琴的问题?

【问题讨论】:

  • 您能描述一下您的问题吗?

标签: twitter-bootstrap ember.js


【解决方案1】:

如果你使用的是 Bootstrap 3 和 Ember 1.0,你应该在你的路由中替换

App.ModalView.create({ title: "My title", content: "My content" }).append();

this.container.lookup('view:modal').append();

为了避免 defaultContainer 弃用 (https://github.com/emberjs/ember.js/issues/2597)

【讨论】:

  • 现在如何将这些参数(标题、内容)传递到视图中?
  • 要传递参数,您可以执行以下操作: var v = this.container.lookup('view:modal'); v.set('title',"我的标题"); v.set('内容', "我的内容"); v.appendTo(App.rootElement);
【解决方案2】:

你的问题在于 css:

在您的ModelView 中有classNames: ["modal", "fade", "hide"],。您必须删除 hide 类。

在模板中你还有另一个问题。您再次使用modalfade。由于您已经在ModelView 中指定了它,所以这是不必要的。

模板

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

因为创建视图时,结果将是 2 个modal 类,并且布局将被破坏:

<div class="modal fade ember-view" >
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

最终结果是这个http://jsfiddle.net/marciojunior/rrXc2/

【讨论】:

  • 那么html类和Ember.view中的classes属性有什么关系呢?这对我来说仍然不是很清楚。
  • 创建 Ember.View 实例时。默认情况下,它的顶部元素是一个没有类的 div 和一个生成的 id。例如:
    ...模板的一些内容...
    。要覆盖它,您可以使用 tagName、classNames 和 elementId。在您的情况下,您通知了 Ember.View 中的 boostrap 模态类和模板,因此更正此问题的选项是:从 Ember.View 中删除类,并保留在模板中,或者相反,就像我所做的那样,从模板中删除,并在 classNames 中设置。
猜你喜欢
  • 2014-05-07
  • 2014-07-21
  • 2017-03-27
  • 2015-01-04
  • 1970-01-01
  • 2014-02-15
  • 1970-01-01
  • 2017-02-21
  • 2015-05-25
相关资源
最近更新 更多