如何从 rails_admin 上的 select 标签获取 (html) id?

How do I get the (html) id from the select tag on rails_admin?

下面的'rails_admin'生成这个HTML,我需要根据这个[=18=中选择的'option'更改另一个'select'标签的选项] 标签,带有 coffescript/jquery。 这个 'select' 标签的 id= 是 "schedule_tasks_attributes_1532831082497_service_id"。 我如何获得这个里面有这个号码的ID?这不是一个固定的数字。

<div class="form-group control-group belongs_to_association_type service_field "id="schedule_tasks_attributes_1532831082497_service_id_field">
  <label class="col-sm-2 control-label" for="schedule_tasks_attributes_1532831082497_service_id">Service</label>
  <div class="col-sm-10 controls">
    <select data-filteringselect="true" data-options="{&quot;xhr&quot;:false,&quot;remote_source&quot;:&quot;/admin/service?associated_collection=service\u0026compact=true\u0026current_action=create\u0026source_abstract_model=task&quot;}" placeholder="Buscar" name="schedule[tasks_attributes][1532831082497][service_id]" id="schedule_tasks_attributes_1532831082497_service_id" style="display: none;">
      <option value=""></option>
      <option value="5">Service 5</option>
      <option value="4">Service 4</option>
      <option value="3">Service 3</option>
      <option value="2">Service 2</option>
      <option value="1">Service 1</option>
    </select>
    <div class="input-group filtering-select col-sm-2" data-input-for="schedule_tasks_attributes_1532831082497_service_id" style="float: left;">
      <input type="text" class="form-control ra-filtering-select-input ui-autocomplete-input" style="display: inline-block;" placeholder="Buscar" required="required" autocomplete="off">
        <span class="input-group-btn">
          <label class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Show All Items" role="button">
            <span class="caret"></span>
            <span class="ui-button-text">&nbsp;</span>
          </label>
        </span>
      </div>
      <a data-link="/admin/service/new?modal=true" class="btn btn-info create" style="margin-left:10px" href="#">
        <i class="icon-plus icon-white"></i>
        Add new service
      </a>
      <a data-link="/admin/service/__ID__/edit?modal=true" class="btn btn-info update disabled" style="margin-left:10px" href="#">
        <i class="icon-pencil icon-white"></i>
        Edit service
      </a>
      <span class="help-block">Required. </span>
    </div>
  </div>

您可以在 jquery 中使用以下代码来 select 提到的 select 标签。

  1. $("[id ^='schedule_tasks_attributes_']")
  2. $("[id $='_service_id']")

如果你想要完美的 selection,你可以使用这个:-

$("select[id ^='schedule_tasks_attributes_'][id $='_service_id']")