2009-07-23 57 views
0

是否有一種更新「link_to_remote」內部文本並保持鏈接功能的高質量方法?基本上我有兩個環節:(Rails)如何在不斷開鏈接的情況下替換「link_to_remote」的文本?

<%= link_to_remote "(#{building.charts.size} Charts)",{:url => {:action => "update_chart_matrix", :chartable_type => "building",:chartable_id => building.id, :title => building.name}, 
    :update => 'chart-matrix', 
} 
%> 

......還有......

<%= link_to_remote "Add Chart",{:url => {:action => "add_chart_for_chartable", :chartable_type => "building",:chartable_id => building.id}, 
    :update => 'other_link', #really not sure about this part as I only want to update the Chart Count in the other link 
} 
%> 

這將是很容易簡單地更換鏈接內的HTML,但我不想要「休息「它的功能。有任何想法嗎?

謝謝。

回答

1

更新的鏈接不會打破onclick功能的內部HTML。您正在使用的原型更新(通過滑軌),其設定的的innerHTML:

update: function(element, content) { 
    element = $(element); 
    if (content && content.toElement) content = content.toElement(); 
    if (Object.isElement(content)) return element.update().insert(content); 
    content = Object.toHTML(content); 
    // This sets innerHTML, it doesn't destroy the object 
    element.innerHTML = content.stripScripts(); 
    content.evalScripts.bind(content).defer(); 
    return element; 
}, 

只要回來的內容是適合居住的a標籤內,你應該罰款。

祝你好運!

相關問題