Rails:用于将大型记录集中的子项添加到 HABTM 关系中的父模型的 UI
给定父/子 HABTM 关系:
class List < ActiveRecord::Base
has_and_belongs_to_many :items
end
class Item < ActiveRecord::Base
has_and_belongs_to_many :lists
end
我需要设置一个 UI 以将项目(子项)从列表创建/编辑表单添加到列表(父项)。问题是项目记录太多而无法使用复选框。最初的想法是有一个弹出窗口,允许用户浏览项目集合以查找要添加的记录,但我不确定这将如何处理新的列表记录(其中父 ID 尚不存在) 。我正在寻找一种解决方案,使用户能够轻松导航大量子记录,并以直观的方式将它们添加到父记录中,并且只需最少的点击次数。
用户需要能够浏览项目记录以找到可接受的选择,因此在这种情况下,强制用户搜索他们想要的记录的自动完成文本框将不起作用。子项目记录由多个属性(例如标题、作者、流派、评级)组织,因此我最初的计划是使用 AJAX 过滤器和排序来设置一个包含项目记录的表,以允许用户将项目集合缩小到所需的元素,然后以某种方式将选定的记录添加到列表中。用户在创建列表时不需要能够定义新的项目记录(即,在创建列表时,用户只需从现有集合中选择多个项目)。
Given the parent / child HABTM relationship:
class List < ActiveRecord::Base
has_and_belongs_to_many :items
end
class Item < ActiveRecord::Base
has_and_belongs_to_many :lists
end
I need to set up a UI to add Items (children) to a List (parent) from the List create / edit form. The wrinkle is that there are far too many Items records to use checkboxes. An initial thought is to have a popup window that allows the user to browse the collection of Items to find the records to add, but I'm not sure how that would work with new List records (where the parent ID would not yet exist). I'm looking for a solution that will make it easy for the user to navigate the large collection of child records and add them to a parent record in an intuitive manner with the minimum amount of clicks required.
Users will need the ability to browse the Item records to find acceptable choices, so an auto-complete text box which would force users to search for records they want will not work in this case. The child Item records are organized with multiple attributes (e.g. title, author, genre, rating), so my original plan was to set up a table with the Item records with AJAX filter and sort to allow the user to narrow down the Item collection to the desired elements, and to then somehow add selected records to a List. Users do not need to be able to define new Item records while creating a list (i.e. when creating a List, the user will simply select multiple Items from the existing collection).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢用于像这样的查找的自动完成文本框;这取决于您的子数据集是否足够直观以供用户猜测。
I like the auto-completing text-box for lookups like this; it'll depend on if your child-data set is intuitive enough for users to guess.