javascript(jquery

编程入门 行业动态 更新时间:2024-10-28 02:32:48
本文介绍了javascript(jquery-rails)在rails 3.1.rc5中无法完全正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每次通过javascript删除对象时,我都使用remove方法不起作用.

every time i use the remove method when deleting object via javascripts it does not work.

我的destroy.js代码如下.

my destroy.js code is as follows.

$("#<%= dom_id(@comment) %>").remove(); $('#comment-count-<%= @parent.id %>').html("<%= pluralize(@parentments.count,'comment')%>");

复数形式很好

我的_comment.html.erb如下

my _comment.html.erb is as follows

<%= div_for comment do %> <% if comment.user.profile.icon.exists? %> <%= image_tag comment.user.profile.icon.url(:small), :alt => comment.user.name, :class => "avatar tip", :title => comment.user.name %> <% else %> <%= image_tag comment.user.gender == 'Female' ? 'missing_woman.png' : 'missing_thumb.png', :alt => comment.user.name, :class => "avatar tip", :title => comment.user.name %> <% end %> <div class="comment-container"> <span><%= link_to comment.user.name, comment.user.profile, :class => "profile-link-small" %></span> <%= commentment%> <div><span style="color:#888;"><%= formatted_time(comment.created_at) %></span> &ndash;&ndash; <span class="rank"><%= comment.user.level %></span> <% if can? :update, comment%> | <span class="del"><%= link_to "Delete", comment, :confirm => "Are you sure you want to delete this comment?", :method => :delete, :remote => true %></span> <% else %> <span class="dialog_link">Delete</span> <% end %> </div> </div> <div class="clear"></div> <% end %>

它曾经可以工作,但在我更新到rails rc5之后它就存储了

It use to work before but after i updated to rails rc5 it storped

推荐答案

您的jQuery这样说:

Your jQuery says this:

$("#<%= dom_id(@comment) %>").remove(); //-------------^

但是您的ERB这样说:

But your ERB says this:

<%= div_for comment do %>

您的 div_for 应该产生HTML是这样的:

Your div_for should produce HTML something like this:

<div id="comment_11"> <!-- ... --> <div>

假设comment是ID为11的Comment对象,则 dom_id 在相同的注释上将产生comment_11,这一切都很好.

Assuming that comment is a Comment object with id 11. Then dom_id on the same comment would produce comment_11 and that's all good.

但是,您正在使用@comment(一个实例变量)来生成jQuery的DOM ID 调用,但HTML的局部变量comment.我猜想comment是正确的,而您正在向dom_id提供nil,结果是ID不匹配,并且您的jQuery没有任何用处.

However, you're using @comment (an instance variable) to generate the DOM ID for the jQuery remove call but the local variable comment for the HTML. I'd guess that comment is the right one and you're feeding a nil to dom_id, the result is that the IDs don't match and your jQuery does nothing useful.

更多推荐

javascript(jquery

本文发布于:2023-10-21 17:42:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:javascript   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!