{ :comm-6ren">
gpt4 book ai didi

javascript - AJAX 请求隐藏文本而不是放置部分

转载 作者:可可西里 更新时间:2023-11-01 01:33:25 24 4
gpt4 key购买 nike

我正在尝试实现带有评论的回复,因此当您单击“回复”时,部分内容应该会显示在当前评论下方。

所以在我的 reply.js.erb 中,我有

$("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('<%= @div_id %>')).show('fast');

其中 @div_id 是它正在回复的评论的部门 ID。所以现在发生的事情是部分不会显示,它还将内容隐藏在@div_id 下。不确定发生了什么。

编辑: 所以,我相信我明白了它被隐藏的原因。我在 Assets 中有另一个名为 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)

".comment"是包含回复链接的部分标题。同一个部分包含一个销毁链接。所以不知何故,当我点击回复时,它也在运行这段代码,它在之后隐藏了评论。这是我的部分评论

%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

我该如何解决这个问题?

最佳答案

可能是 @div_id 没有 #,所以在 @div_id< 之前添加 # 之后下面的代码可能会工作

$("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('#<%= @div_id %>')).show('fast');

关于javascript - AJAX 请求隐藏文本而不是放置部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32114574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com