0

我刚开始使用 RJS,这很棒,但是我习惯于在 link_to_remote 等中放置视觉效果,我不确定如何在触发遥控器之前和之后触发动作。

以这个链接为例:

HTML

<span id="<%= "edit_comment_link_#{comment.id.to_s}"%>" style="float:left;"> 
<%= link_to_remote "edit", {:update => "comment_#{comment.id.to_s}", :url => edit_post_comment_path(comment.post, comment), :method => :get}%> | </span>

控制器:

def edit
  @comment = Comment.find(params[:id]) 
  respond_to do |format|
    #format.html render edit_comment_path(@comment)
    format.js 
  end
end

RJ:

page.replace_html "edit_comment_link_#{@comment.id.to_s}", "currently editing | "

那么 RJS 是否主要用于渲染动作后的视觉效果,例如微调器应该放入 link_to_remote 中call_backs?这是做事的好方法吗?

4

1 回答 1

0

你是这个意思吗?

<%= link_to_remote '<span>edit</span>', 
        :url => edit_post_comment_path(comment.post, comment),
        :method => :get,
        :loading => "Element.show('spinner')",
        :complete => "Element.hide('spinner')" -%>

在 rjs 文件中,您可以使用 page.delay 堆叠效果/事件:

  item = "edit_comment_link_#{@comment.id.to_s}"
  page.replace_html  item,  :text => 'currently editing | '
  page.visual_effect :fade, item, :duration => 0.5
  page.delay 0.5 do
    page.visual_effect :highlight, "other_dom_object", :duration => 0.5
  end

更多关于 rjs 事件的信息:JavaScriptGenerator API Docs

于 2010-05-26T19:06:44.640 回答