Jil*_*ill 15 javascript ajax jquery ruby-on-rails
我正在尝试使用注释实现回复,因此当您单击"回复"时,部分应显示在当前注释下方.
所以在我的reply.js.erb中,我有
$("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('<%= @div_id %>')).show('fast');
Run Code Online (Sandbox Code Playgroud)
其中@div_id是其回复的评论的分部ID.所以现在发生的事情是部分不会显示,而且它也隐藏了@div_id下面的内容.不知道发生了什么事.
编辑:所以,我相信我弄明白为什么它被隐藏了.我在资产中有另一个名为comments.js.coffee的javascript文件,其中包含以下内容:
jQuery ->
$(document)
.on "ajax:beforeSend", ".comment", ->
$(this).fadeTo('fast', 0.5)
.on "ajax:success", ".comment", ->
debugger;
$(this).hide('fast')
.on "ajax:error", ".comment", ->
debugger;
$(this).fadeTo('fast', 1)
Run Code Online (Sandbox Code Playgroud)
".comment"是包含Reply链接的partial的标题.同一部分包含Destroy链接.所以当我点击"回复"时,它也会运行此代码,之后会隐藏评论.这是我的评论部分
%div.comment{ :id => "comment-#{comment.id}" }
%hr
= link_to "×", comment_path(comment), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this comment?", :disable_with => "×", :class => 'close'
%h4
= comment.user.first_name
%small= comment.updated_at
%p= comment.body
%p= link_to "Reply", comment_reply_path(comment), :method => :get, :remote => true
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
可能@div_id是没有#用的,所以下面的代码可以在前面加上工作后,#前@div_id
$("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('#<%= @div_id %>')).show('fast');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1154 次 |
| 最近记录: |