Tôi đã tìm thấy dự án Bootstrap Select này và gem for Rails của nó. Tôi muốn thực hiện tìm kiếm trong thẻ chọn.Làm cách nào để thêm thuộc tính dữ liệu trong thẻ chọn biểu mẫu Rails?
tôi làm kiểm tra phần tử và đây là nguồn HTML:
<select class="selectpicker" data-live-search="true">
<option>Hot Dog, Fries and a Soda</option>
<option>Burger, Shake and a Smile</option>
<option>Sugar, Spice and all things nice</option>
</select>
Làm thế nào để thêm data-live-search="true"
bên chọn thẻ hình thức của tôi?
hình thức của tôi chọn:
<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker"} %>
Những gì tôi đã cố gắng:
<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker", data: "live-search"} %>
Nhưng nó không làm việc.
bạn đã thử '{class: "hình thức kiểm soát selectpicker", "dữ liệu trực tiếp tìm kiếm" => "true"} '? –
Hoặc, 'dữ liệu: {'live-search' => 'true'}'. –
'{class:" selectpicker form-control "," data-live-search "=>" true "}' hoạt động. Nhưng phần tìm kiếm hiện không hoạt động. Kỳ dị. –