Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails模型中数组中的两个相关下拉菜单项_Javascript_Jquery_Ruby On Rails_Drop Down Menu - Fatal编程技术网

Javascript Rails模型中数组中的两个相关下拉菜单项

Javascript Rails模型中数组中的两个相关下拉菜单项,javascript,jquery,ruby-on-rails,drop-down-menu,Javascript,Jquery,Ruby On Rails,Drop Down Menu,我在谷歌上搜索了几个小时,但没有找到任何符合我要求的东西。我是rails新手,正在rails 4.2.4中开发一个bug跟踪系统。这里有一个名为Bug的类。关于Bug的创建,我有两个下拉菜单,其中将填充来自模型的数组值。我的模型如下所示: class Bug < ActiveRecord::Base belongs_to :creator, :class_name => "User", :foreign_key => "creator_id" belongs_t

我在谷歌上搜索了几个小时,但没有找到任何符合我要求的东西。我是rails新手,正在rails 4.2.4中开发一个bug跟踪系统。这里有一个名为Bug的类。关于Bug的创建,我有两个下拉菜单,其中将填充来自模型的数组值。我的模型如下所示:

class Bug < ActiveRecord::Base
    belongs_to :creator, :class_name => "User", :foreign_key => "creator_id"
    belongs_to :developer, :class_name => "User", :foreign_key => "developer_id"

    TYPE = ['Feature', 'Bug']
    FEATURE_STATUS = ['New', 'Started', 'Completed']
    BUG_STATUS = ['New', 'Started', 'Resolved']

    validates :title, :presence => true, :uniqueness => true
    validates :status, :type, :presence => true

    has_attached_file :screen_shot
    validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

end
类错误“User”,:foreign\u-key=>“creator\u-id”
属于:开发者,:类名=>“用户”,:外键=>“开发者id”
类型=['Feature','Bug']
功能状态=[“新建”、“已启动”、“已完成”]
BUG_STATUS=[“新建”、“已启动”、“已解决”]
验证:title,:presence=>true,:university=>true
验证:status,:type,:presence=>true
已附加文件:屏幕截图
验证附件内容类型:图像、内容类型=>[“图像/jpg”、“图像/jpeg”、“图像/png”、“图像/gif”]
终止
_form.html.erb文件中有一些代码将显示下拉选项:

...
...
...
<div class="form-group">
    <%#= f.label :bug_type, class: "col-sm-2 control-label" %>
    <%= f.label :bug_type, t('.bug_type') + ":" %>
    <%= f.select :bug_type,
    Bug::TYPE,
    :prompt => "Select bug type:"
    %>
</div>
<div class="form-group">
    <%#= f.label :status, class: "col-sm-2 control-label" %>
    <%= f.label :status, t('.status') + ":" %>
    <%= f.select :status,
    Bug::FEATURE_STATUS,
    :prompt => "Select status:"
    %>
</div>

...
...
...
。。。
...
...
“选择错误类型:”
%>
“选择状态:”
%>
...
...
...
目前,我的代码在第一个下拉列表中显示array Bug::TYPE的值,在第二个下拉列表中显示Bug::FEATURE_STATUS的值。我的问题是如何根据第一个下拉列表的值使用数组值填充第二个下拉列表?也就是说,如果用户从第一个下拉列表中选择值“Feature”,则第二个下拉列表应显示Feature_STATUS array的值。如果用户从第一个下拉列表中选择一个值'Bug',则第二个下拉列表应显示array FEATURE_Bug的值


我是一个新来的层叠流动,这是我在这里问的第二个问题。我们将非常感谢您的帮助。提前感谢。

您必须使用JQuery才能做到这一点:

$('#select_id').on('change', function() {
  //populate the second one here
});
然后在此处查看有关如何填充select的更多详细信息: