当这些 div 是新的时切换多个 div(无 ID)

发布于 2024-09-28 09:23:52 字数 631 浏览 0 评论 0原文

我将 div 切换与复杂形式结合起来: http://railscasts.com/episodes/ 75-complex-forms-part-3

我的具体情况:我在 table/new.html.erbCustomer/_customer_note_fields 中构建了一些嵌套字段>。通常,我会执行类似以下操作来切换 div:

# view
<a class="toggle" rel="toggle[expand#<%= note.id %>]">"Click me"</a>

<div class="expand_me" id="<%= "expand#{note.id}" -%>">
"Hello!"
</div>

当前情况的问题是它位于表单生成器的中间,其中所有记录都是新的 - 因此,它们没有 ID!因此,这些 div 没有唯一的标记。

我可以访问属于新的未保存记录的其他唯一编号吗?你会如何处理这个问题?

I am combining div toggling with complex forms: http://railscasts.com/episodes/75-complex-forms-part-3

My specific situation: I have a few nested fields being built in table/new.html.erb and Customer/_customer_note_fields. Ordinarily, I would do something like the following to have toggled divs:

# view
<a class="toggle" rel="toggle[expand#<%= note.id %>]">"Click me"</a>

<div class="expand_me" id="<%= "expand#{note.id}" -%>">
"Hello!"
</div>

The problem with the current case is that it is in the middle of a form builder where all the records are new - therefore, they have no IDs! Therefore, there is no unique marker for these divs.

Is there some other unique number belonging to a new unsaved record that I can access? How would you deal with this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奶茶白久 2024-10-05 09:23:52

记录没有 id,但对象本身有。尝试调用对象的 id,我的意思是文字 ruby​​ 对象 id,而不是 object.id

例如:

a = "Just an example"
a.object_id = 39402342

所以你可以使用它作为唯一编号

the records don't have ids but the objects themselves do. try calling the id of the object by which I mean the literal ruby object id not object.id

for example:

a = "Just an example"
a.object_id = 39402342

so you can use that as the unique number

吖咩 2024-10-05 09:23:52

萨姆的想法可行。尝试使用 note.object_id 并看看效果如何。您还可以尝试根据对象的某些数据创建 MD5 或 Base64 字符串。

Sam's idea would work. Try using note.object_id and see how well it goes. You could also try to create a MD5 or Base64 string based on some data of the object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文