簡體   English   中英

根據用戶在Rails中的選擇獲取記錄

[英]Fetching records based on user selection in rails

我有一個帶有category_id和subcategory_id屬性的着裝模型,我想制作一個衣服模型,以便當用戶從collection_select中選擇一個類別類型時,該表單將以復選框的形式更新為該類別的子類別,以供用戶檢查他需要的子類別,我可以通過$('#dress_category_id')。change來檢測何時使用javascript更改了選擇,以及通過$('#dress_category_id:selected')。text()選擇了哪種類別類型,但我不知道,而我的搜索時間卻徒勞無功,如何使用子類別模型中的數據更新其他表單字段。

這是我的表單代碼:

<div id="" class="modal-form no-shadow eighty-margin-top">
  <div class="modal-header">
  </div>
  <div class="form-box">
    <header class="ui-min-header">
      <h3 class="letter_pressed light_header ">New Design</h3>
    </header>
    <div class="form-body  row-fluid" style="margin-top: 20px;">
      <%= form_for( @dress, :html => {class: "form-horizontal", role:"form" }) do |f| %>
          <%= render "error_messages", target: @dress %>

          <div class="form-group" id="avatar">
            <%= f.label :category, class: "col-lg-3 control-label" %>
            <div class="col-lg-9">
              <%= f.collection_select :category, Category.all, :id, :name, {:prompt=> "Select a category"}, {class: "form-control input-lg"} %>
            </div>
          </div>
            </div>
          </div>
子類別在這里->
  <div class="form-group"> <%= f.label :name, class: "col-lg-3 control-label" %> <div class="col-lg-9"> <%= f.text_field :name, placeholder: "Name of your design", class: "form-control" %> </div> </div> <div class="form-group"> <%= f.label :keywords, class: "col-lg-3 control-label" %> <div class="col-lg-9"> <%= f.text_field :keywords, class: "form-control" %> </div> </div> <div class="form-group"> <%= f.label :description, class: "col-lg-3 control-label" %> <div class="col-lg-9"> <%= f.text_field :description, placeholder: "About your design", class: "form-control" %> </div> </div> <div class="form-group"> <div class="col-lg-offset-3 col-lg-9"> <button type="submit" class="btn btn-warning">Continue</button><br/> </div> </div> <% end %> </div> </div> </div> 

您可能會看一下jQuery Cascading Dropdown Plugin 您可以直接使用它,也可以查看其效果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM