(Rails)如何在不破坏链接的情况下替换“link_to_remote”的文本?

时间:2009-07-23 04:18:51

标签: javascript ruby-on-rails updating link-to-remote

是否有更好的方法来更新“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 个答案:

答案 0 :(得分:1)

更新链接的内部HTML不会破坏onclick功能。你正在使用原型中的更新(通过Rails),它设置了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标记内,您就可以了。

祝你好运!

相关问题