【发布时间】:2012-11-24 23:05:42
【问题描述】:
我正在尝试为我的每个帖子生成一个模态,以便每个帖子都有一个包含帖子内容(最终是 cmets)的模态。单击评论链接时,将出现模式。问题是我必须为每个帖子创建一个引导模式块,所以我决定在我的主干模板中这样做是最简单的。为什么这不起作用?
这是我的代码:
app/assets/templates/posts/index.jst.eco
<% for post in @posts.models: %>
<tbody><td>
<%= post.get('content') %>
</td></tbody>
<tr><td>
<a href="#<%= post.get('id') %>">Comment</a>
</td></tr>
<div class="modal" id="post-<%= post.get('id')%>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<%= post.get('content') %>
</div>
</div>
<% end %>
app/assets/javascripts/routers/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 控制台没有错误,模态框似乎没有出现。 每个帖子都有一个模态块,其 html id 字段等于“post-(the posts id)”
非常感谢任何帮助!
【问题讨论】:
-
检查是
$("#post-#{id}")还是$("#post-{id}")? -
是的,我确定,主干运行正常,但我的引导模式运行不正常。这是一个针对引导模式在主干视图使用的生态模板中起作用的问题
标签: jquery ruby-on-rails-3 backbone.js twitter-bootstrap eco