jquery.taiwan_city.js.coffee 548 B

123456789101112131415
  1. (($) ->
  2. $.fn.taiwan_city = () ->
  3. @each ->
  4. selects = $(@).find('.city-select')
  5. selects.change ->
  6. $this = $(@)
  7. next_selects = selects.slice(selects.index(@) + 1) # empty all children city
  8. $("option:gt(0)", next_selects).remove()
  9. if next_selects.first()[0] and $this.val() # init next child
  10. $.get "/taiwan_city/#{$(@).val()}", (data) ->
  11. next_selects.first()[0].options.add(new Option(option[0], option[1])) for option in data
  12. $ ->
  13. $('.city-group').taiwan_city()
  14. )(jQuery)