【发布时间】:2013-10-08 01:13:28
【问题描述】:
-@things.each do |thing|
%div.thing
= thing
我见过几种不同的技术。但是使用上面的 HAML 模板,我希望每个 thing 都有一个从 1 到 n+1 的唯一 ID。为所有 things 动态增加 id 的最佳方法是什么?
例如:对于 n 事物,我希望 HTML 看起来像这样。
<div class='thing' id='1'>
<div class='thing' id='2'>
...
<div class='thing' id=n+1>
【问题讨论】:
-
ID 不能以整数开头,它是无效的。
-
您可以在末尾添加递增的 id 编号,只需给它一个以
thing开头的 id,然后您可以执行thing1thing2thing3等 -
@PatrickEvans 可以。但是你确定ID的事情吗?我正在加载一个页面来测试它,这很好@KeithJohnson 请参阅this question 了解可接受的 ID。@PatrickEvans 好的链接谢谢!
标签: html ruby-on-rails haml