mercredi 15 mars 2017

Accessing rails loop variable in JQuery

I have the following html code:

.panel
.row
  .columns.small-6.medium-4
    = city_business_units_select_tag @appointment
  .columns.small-6.medium-4
    = select_tag 'appointment[asset_id]', options_for_select(current_cbu.assets.collect{|asset| [ asset.name, asset.id ] }, @appointment.asset_id), include_blank: true

.row
  .columns.small-6.medium-4
    =f.label :technician_id
    =f.select :technician_id, Technician.order(:last_name, :first_name).map {|t| [t.full_name, t.id]}, {selected: @technician_id, prompt: 'Select Technician', include_blank: true}

So basically when the city_business_units_select_tag is changed, i want to hide certain elements on the technician select using jquery. How do I get the variable "technician" for each option object as I loop over it?

    $("#appointment_city_business_unit_id").change(function(){
       $("#appointment_technician_id > option").each(function () {
          console.log(technician.city_buiness_unit);
       });
    });

Aucun commentaire:

Enregistrer un commentaire