如何从模型中为HTML标记生成唯一的dom ID [英] How can I generate a unique dom id for a html tag from model
本文介绍了如何从模型中为HTML标记生成唯一的dom ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个索引视图,其中包含具有多个属性的项目的几行.我想用ajax更新item属性的内容,因此我需要一个唯一的dom id.有没有可用的辅助方法? 我现在正在做的是:
I am having an index view with several rows for items which have multiple attributes. I would like to update the content of an items attribute with ajax, therefore I need a unique dom id. Is there a helper method available? What I am doing right now is:
<span id="<%= item.id.to_s + "_on_storage"%>">
最好, 菲尔
推荐答案
您可以使用
dom_id(item)
这是用于生成DOM ID的ActiveRecord方法.
Which is an ActiveRecord method for generating DOM IDs.
这篇关于如何从模型中为HTML标记生成唯一的dom ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文