我在執行(動態選擇菜單在railscast情節)時遇到了問題,因爲它無法正常工作。 (國家)菜單提供了所有可用選項(國家+國家)。#88動態選擇菜單(修訂版)無法在導軌上工作
我跟着視頻一步一步地尋找可用的解決方案,但沒用,但有一個問題,我無法弄清楚。
coffescript(people.js.coffee)
jQuery ->
states = $('#person_state_id').html()
$('#person_state_id').parent().hide()
$('#person_country_id').change ->
country = $('#person_country_id :selected').text()
escaped_country = country.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
options = $(states).filter("optgroup[label='#{escaped_country}']").html()
console.log(options)
if options
$('#person_state_id').html(options).parent().show()
else
$('#person_state_id').empty().parent().hide()
new.html.erb
新出生
<%= form_for @person do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :country_id %><br />
<%= f.collection_select :country_id, Country.order(:name), :id, :name, include_blank: true %>
</div>
<div class="field">
<%= f.label :state_id, "State or Province" %><br />
<%= f.grouped_collection_select :state_id, Country.order(:name), :states, :name, :id, :name, include_blank: true %>
</div>
<div class="actions"><%= f.submit %></div>
<% end %>
我也找到了解決更新(寶石「的jQuery的的Gemfile -turbolinks') 和application.js文件(// = require jquery.turbolinks),但是沒用。
請大家幫忙。
謝謝,但不幸的是,問題依然存在。 –
此外,嘗試刪除jQuery後的白線 - >。咖啡語法有點棘手。 –
我刪除了它,但沒有任何意義。 –