Rails3-jquery-completamento automatico plug-in? Sembra che non supporti il completamento automatico multiplo, è necessario modificare il codice del plugin !! Se insisti sulle tue idee precedenti, segui i miei passi.
- corsa
bundle show rails3-jquery-autocomplete
per ottenere il plugin di lavoro directroy
- compagno /lib/autocomplete.rb
modificare il define_method
in questo modo:
define_method("autocomplete_#{object}_#{method}") do
arr = params[:term].split(",")
unless params[:term] && params[:term].empty?
items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{arr[arr.size-1]}%"]).limit(limit).order(order)
else
items = {}
end
render :json => json_for_autocomplete(items, method)
fine
modificare autocomplete-rails.js
come questo function split(val) { return val.split(/,\s*/); } function extractLast(term) { return split(term).pop(); } $(document).ready(function(){ $('input[autocomplete]').each(function(i){ $(this).autocomplete({ source: $(this).attr('autocomplete'), focus: function() { return false; }, select: function(event, ui) { var terms = split(this.value); // remove the current input terms.pop(); // add the selected item terms.push(ui.item.value); // add placeholder to get the comma-and-space at the end terms.push(""); this.value = terms.join(","); return false; } }); }); });
riavviare il server e provare
!! ricorda che è meglio eseguire il backup di autocomplete.rb per evitare sovrascritture dopo aver eseguito l'installazione del pacchetto.
Buona fortuna!
Puoi pubblicare il codice che hai già provato? e poi cosa c'è che non va nell'output? –
Hai bisogno di usare il plugin per rails? Suppongo che sarebbe più semplice aggiungere il plugin jquery-ui ai javascript e configurarlo in javascript. – skalee