2011-08-21 36 views
1

我想,當它使用此代碼的第二行發佈到突出新的消息@micropost但我沒有任何成功:如何使新發布的評論選擇器在jquery(與rails)?

$("table.microposts").prepend("<%= escape_javascript(render(:partial => 'shared/feed_item', :object => @micropost)) %>"); 

$("#table.micropost_<%= @micropost.id %>").effect("highlight", {}, 3000); 

$("#new_micropost")[0].reset(); 

這是飼料項目部分(我嘗試使用div_for功能以確定新的職位...:

<tr> <%= div_for feed_item do %> 
    <td class="gravatar"> 
     <%= link_to gravatar_for(feed_item.user), feed_item.user %> 
    </td> 
    <td class="micropost"> 
     <span class="user"> 
      <%= link_to feed_item.user.name, feed_item.user %> 
     </span> 
     <span class="content"> 
      <%= feed_item.content %> 
     </span> 
     <span class="timestamp"> 
      Posted <%= time_ago_in_words(feed_item.created_at) %> ago. 
     </span> 
    </td> 
    <% if current_user?(feed_item.user)%> 
     <td> 
      <%= link_to "delete", feed_item, :method => :delete, 
              :confirm => "You sure?", 
              :title => feed_item.content %> 
     </td> 
    <% end %> 
<% end %> 

</tr> 

<% if @feed_items.any? %> 
    <table class="microposts" summary="Status feed"> 
     <%= render :partial => 'shared/feed_item', :collection => @feed_items %> 
    </table> 
    <%= will_paginate @feed_items %> 
<% end %> 

希望給足夠的細節感謝所有幫助

回答

1

可以使用prependTo代替prepend,然後做這樣:

$("<%= escape_javascript(render(:partial => 'shared/feed_item', :object => @micropost)) %>"). 
    prependTo($("table.microposts")). 
    effect("highlight", {}, 3000); 
+0

謝謝,奇怪它沒有工作,但? – WillLA

+0

@will Sentance你有沒有js錯誤?新評論/微博是否添加到頁面? – rubish

+0

對於這兩個版本,新評論/微博確實會添加(不按預期重新加載頁面) – WillLA

-1

您需要的.live()函數,如果你的頁面加載後添加的東西(即預先)

看一看這裏:http://api.jquery.com/live/

+0

的選擇是關閉的,還有在這種情況下沒有必要的現場。 – rubish

+0

我誤解了你的問題。對於那個很抱歉! – madc