如何让记录可移动?
在 Rails 3.1 中,
我想让数据库记录可移动,并在 ecah one 中使用“上移”和“下移”链接。例如,如果我有 4 条记录:
标题 1 [上] [下]
标题 2 [上] [下]
标题 3 [上] [下]
标题 4 [上] [下]
我可以单击标题 3 的上链接新表格将为:
标题 1 [上] [下]
标题 3 [上] [下]
标题 2 [上] [下]
标题 4 [上] [下]
In rails 3.1
I want to make the db records movables, with a Move up and a Move down link in ecah one. For example, if I have 4 records:
Title 1 [up] [down]
Title 2 [up] [down]
Title 3 [up] [down]
Title 4 [up] [down]
I could click in the Title 3's up link and the new table would be:
Title 1 [up] [down]
Title 3 [up] [down]
Title 2 [up] [down]
Title 4 [up] [down]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将订单字段添加到表中。然后,当用户单击向上移动或向下移动时,从该字段中添加或减去 1。确保此字段不会低于 0 或高于表中的条目数 - 1。当您不想按顺序显示这些字段时,只需按此字段排序即可。
在数据库中“上下”移动行(SQL查询帮助)
Add an Order field to the Table. Then when the person clicks the move up or move down, add or subtract 1 from that field. Make sure this field doesn't go below 0 or above the number of entries - 1 in your table. When you wan't to display these fields in order, just order them by this field.
Moving rows 'up and down' in a database (SQL query help)