pur*_*ice 3 jquery ruby-on-rails popover twitter-bootstrap
我在Rails 3中使用Twitter引导程序弹出窗口.
当我最初加载页面(显示操作)时,弹出窗口正常工作.
我的部分(一个叫另一个)看起来像这样:
<span class="solution_votes_stat" id="<%= 'solution_votes_stat_' + sid.to_s %>">
<%= render :partial => 'solutions/popover', :locals => {:s => s} %>
</span>
Run Code Online (Sandbox Code Playgroud)
_popover.html.erb看起来像这样:
<% sid = s.id %>
<% solution_vote_up_count = s.solution_votes.votes_up.count %>
<% all_users_who_voted_up(sid) %>
<span class = "popover-with-html" rel = "popover"
data-original-title = "Who likes this"
data-content = "<%= render :partial => 'solutions/users_who_voted_up', :locals => {:users_who_voted_up => @users_who_voted_up} %>"
id="<%= 'solution_' + sid.to_s + '_up_votes' %>">
<%= solution_vote_up_count %>
</span>
<%= solution_vote_up_count==1 ? "Advisor" : "Advisors" %>
Run Code Online (Sandbox Code Playgroud)
这会产生这样的HTML:
<span class="solution_votes_stat" id="solution_votes_stat_1">
<span class = "popover-with-html" rel = "popover"
data-original-title = "Who likes this"
data-content = "<ul><li>Admin</li></ul>"
id="solution_1_up_votes">1
</span>
Advisor
</span>
Run Code Online (Sandbox Code Playgroud)
到目前为止,这么好=>一切正常.
问题是当我尝试使用jQuery更新它时.
在我的up_votes.js.erb中,我有:
update_popover = ('<%= escape_javascript(render(:partial => "solutions/popover", :locals => {:s => @solution}))%>');
$('<%= "#solution_votes_stat_"+@solution.id.to_s %>').html(update_popover);
作为测试,我点击了投票,然后投票.当我查看生成的HTML时,它看起来与上面的一样完全相同,只是它现在不起作用(没有弹出)这个div; popover仍在处理所有其他div(使用相同的HTML).
关于发生了什么以及如何解决这个问题的任何想法?
更新:看起来它正在缓存它.我点击了投票来查看div HTML是什么,在Chrome开发人员中,HTML是正确的(0票等)但是当我查看页面源时,它没有改变(1票等).仍然不知道该怎么办呢...我想直接使用jQuery修改数据/ attr而不是渲染部分?仍然......为什么不再使用popover,即使使用缓存数据?
有没有想过给自己一个快速的踢?:)好吧,我想通了.在我的solutions.js.coffee(在assets文件夹中),我有这个jQuery在加载文档时触发它:
$('.popover-with-html').popover({ html: true })
Run Code Online (Sandbox Code Playgroud)
当我将此行添加到我更新数据的up_votes.js.erb文件中时,它会重新加载数据并正确显示.呃 - 整整一天都烧了 - 但我猜你有时会这样学习.:|
归档时间: |
|
查看次数: |
2731 次 |
最近记录: |