2009-07-23 55 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标签内,你应该罚款。

祝你好运!

相关问题