(Rails) 如何替换“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 就足够容易了,但我不想“破坏”其功能。 有任何想法吗?
谢谢。
Is there a quality way to update the text inside a "link_to_remote" and leave the link functional? Basically I have two links:
<%= 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',
}
%>
...and...
<%= 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
}
%>
It would be easy enough to simply replace the HTML inside the link, but I don't want to "break" its functionality. Any ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新链接的内部 HTML 不会破坏
onclick
功能。 您正在原型中使用更新(通过Rails),它设置了innerHTML:只要返回的内容适合存在于
a
标签内,您应该没问题。祝你好运!
Updating the internal HTML of a link won't break the
onclick
functionality. You're using update in prototype (via Rails), which set's the innerHTML:As long as the content coming back is suitable to live inside an
a
tag, you should be fine.Good luck!