Backbone,模板内的Bootstrap模态未显示

我正在尝试为每个post生成一个模态,以便每个post都有一个包含post内容的模式(最终是评论)。 单击注释链接时,将显示模式。 问题是我必须为每个post创建一个bootstrap模态块,所以我决定在我的骨干模板中这样做最容易。 为什么这不起作用?

这是我的代码:

应用程序/资产/模板/职位/ index.jst.eco

     <a href="#">Comment  <div class="modal" id="post-" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">  

应用程序/资产/ Java脚本/路由器/ posts_router.js.coffee

 class Voice.Routers.Posts extends Backbone.Router routes: '': 'index' ':id': 'show' initialize: -> @collection = new Voice.Collections.Posts() @collection.fetch() index: -> view = new Voice.Views.PostsIndex(collection: @collection) $('#container').html(view.render().el) show: (id) -> $("#post-#{id}").modal('show') 

js控制台中没有错误,似乎没有显示模态。 每个post都有一个模态块,其html id字段等于“post-(postid)”

任何帮助深表感谢!

这听起来与Bootstrap模态和使用Backbone的很多SO问题非常类似。 从Dereck Bailey查看此解决方案,

http://lostechies.com/derickbailey/2012/04/17/managing-a-modal-dialog-with-backbone-and-marionette/

 // the template  // the html has only one modal div  // inside your show router function var view = new MyView(); view.render(); var $modalEl = $("#modal"); $modalEl.html(view.el); $modalEl.modal(); 

他的解释是,

人们在使用modal dialog时遇到的问题的核心是模态插件从DOM中删除包装模态的DOM元素。 它通常被添加到一些特殊的保持位置,其中模态插件可以保证在打开模式对话框之前元素不可见。 我过分概括了一下,但许多modal dialog以这种方式或以类似的方式工作。

这通常导致的问题是,当DOM元素被modal dialog移动时,Backbone视图将失去它的事件处理。 当modal dialog从DOM中删除视图的elevents配置将丢失,因为DOM元素已从DOM移动或移除,并且jQuery必须放弃事件。 当el重新添加到DOM以将其显示为模态时,则不会重新附加events