0

REQUEST フォームには多くの CATEGORIES があり、CATEGORY には多くの PRODUCTS があります。カテゴリを選択して、製品選択リストに入力します。jQuery は次のとおりです。

jQuery ->
    $('#request_product_id').parent().hide()
    products = $('#request_product_id').html()
    console.log(products)
    $('#request_category_id').change ->
        category = $('#request_category_id :selected').text()
        options = $(products).filter("optgroup[label=#{category}]").html()
        console.log(options)
        if options
            $('#request_product_id').html(options)
            $('#request_product_id').parent().show()
        else
            $('#request_product_id').empty()
            $('#request_product_id').parent().hide()

部分的なフォームは次のとおりです。

<div class="field">
    <%= f.label :category_id, "Select a Category:" %>
    <%= f.collection_select(:category_id, Category.sorted, :id, :name, :include_blank => true ) %>
  </div>

  <!--  BASED ON CATEGORY SELECTED ABOVE, LOAD CORRESPONDING PRODUCTS BELOW -->

  <div class="field">
    <%= f.label :product_id, "Select a Product/Service:" %>
    <%= f.grouped_collection_select :product_id, Category.sorted, :products, :name, :id, :name, include_blank: true %>
  </div>

これは、カテゴリ名にスペースが含まれていない場合はうまく機能しますが、スペースが含まれていると、製品リストが読み込まれません。例: category.name = "Software" or "Personnel" - すべてのソフトウェアまたは人事製品を正常にロードします。ただし、category.name = "Application Development" または "Business Objects Report" の場合、何も読み込まれません。

どうして?前もって感謝します!

4

2 に答える 2

0

options = $(products).filter("optgroup[label='#{category}']").html()jQueryで 試してみてください。

于 2013-07-23T14:44:06.420 に答える
0

私はそれを理解しました-#categoryを一重引用符で囲みました:

options = $(products).filter("optgroup[label='#{category}']").html()

話させてくれてありがとう!:)

于 2013-07-23T14:44:17.233 に答える