链接列表相关选择框

发布于 2024-08-23 07:21:50 字数 777 浏览 4 评论 0原文

所以我这样做的时间不长,但我完全坚持下去。我有一个如下所示的模型(为简洁起见进行了简化):

class ReqBreakdown < ActiveRecord::Base
  belongs_to :next_level #nil if lowest level
  belongs_to :previous_level #nil if highest level
  belongs_to :requirement_level
end

我需要一种从 UI 构建这些列表的方法。我最初设想使用链接的下拉菜单,如下所述: http://blog.jatinder.me/2006/09/cascading-select-boxes-with-rjs.html 但我什至无法让它在我的控制器上调用操作。我将描述的 javascript 复制到我的 application.js 中,确保它包含在我的布局中,将帮助器添加到 application_helper.rb 中,并将支持操作添加到我的控制器中,但没有运气。老实说,我什至不确定它是否能满足我的要求。 选择规则为:

  1. 最多 4 个级别(即 4 个选择框)。
  2. 没有循环引用(即必须从下一个要选择的文本框中删除所有先前选择的项目)
  3. 所选对象都是同一类型(requirement_level)

有什么建议吗?

So I haven't been doing this for long but I'm completely stuck on this. I have a model which looks like this (simplified for brevity):

class ReqBreakdown < ActiveRecord::Base
  belongs_to :next_level #nil if lowest level
  belongs_to :previous_level #nil if highest level
  belongs_to :requirement_level
end

I need a way to build these lists from the UI. I had initially envisioned using linked drop-downs like those described here: http://blog.jatinder.me/2006/09/cascading-select-boxes-with-rjs.html but I can't even get it to call the action on my controller. I copied the described javascript into my application.js, made sure it was included in my layout, added the helper to application_helper.rb, and added the supporting actions to my controller, but no luck. Honestly, I'm not even sure it will meet my requirements.
The rules for selection are:

  1. Up to 4 levels (i.e. 4 select boxes).
  2. No circular references (i.e. all previously selected items must be removed from the next text-box to be selected)
  3. Selected objects are all of the same type (requirement_level)

Any suggestions?

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

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

发布评论

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

评论(1

无需解释 2024-08-30 07:21:50

既然您还处于起步阶段,我可以建议您观看精彩的 Railscasts 剧集吗?特别是这里的一个:

我知道这可能不是您正在寻找的答案,但是由于您在连接控制器以执行您想要的任何操作时遇到困难,因此您的问题可能真的在任何地方。 Ryan(railscasts 的作者)很好地解释了这些小东西,并为他的所有剧集提供了完整的源代码。

如果这是我,我可能会做两件事之一。

  1. 放弃 rjs,并使用 jquery 客户端来完成几乎所有事情。 jquery 在这方面确实很出色。如果数据列表是静态的,那就更好了,但如果不是,您可以使用 ajax 随时更新内容。
  2. 查看不同的 UI 元素,可能是一个多选框或一组复选框,具体取决于具体情况。

我对你正在寻找的方向没有问题,但由于你对这个问题的技术细节有点了解,我实际上只是提供一些一般性建议,而不是具体的答案。

祝你好运!

Since you are still getting starting, might I suggest you watch the excellent railscasts episodes? Particularly the one here:

I know this may not be the answer you are looking for, but since you are having trouble getting your controller hooked up to do anything you want, your issue could really be anywhere. Ryan (author of railscasts) does a great job explaining the small stuff, as well as providing full source code to all his episodes.

If this were me, I would probably do one of two things.

  1. Ditch rjs, and use jquery client side for pretty much the whole thing. jquery really excels here. If the list of data is static, all the better, but if not you can use ajax to update things for you as you go.
  2. Look at a different UI element, perhaps a multi-select box or group of checkboxes, depending on the situation.

I have no problem with the direction you are looking but since you are a bit light on technical details for the question, I'm really just giving some general advice rather than a specific answer.

Good luck!

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