Rails:用于将大型记录集中的子项添加到 HABTM 关系中的父模型的 UI

发布于 2024-09-07 22:28:45 字数 602 浏览 3 评论 0原文

给定父/子 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 技术交流群。

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

发布评论

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

评论(1

我是男神闪亮亮 2024-09-14 22:28:45

我喜欢用于像这样的查找的自动完成文本框;这取决于您的子数据集是否足够直观以供用户猜测。

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.

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