這是使用rails
和產品散列typeahead
如何使用typeahead在自動完成期間返回其他值?
def autocomplete
render json: Product.ac_search(params[:query].to_s)
end
$ ->
$('#order_id').typeahead
name: "name"
valueKey: "name"
remote: "/products/autocomplete?query=%QUERY"
= simple_form_for @order do |form|
= form.input :product_id, as: :string
比如我實現自動完成的:
[{"id":"8004","name":"cow leg"}, {"id":"8004","name":"dog leg"}]
如何通過返回按名稱選擇項目,如果產品的ID?
插件,你使用的是什麼預輸入....應該有一個'select'事件回調,它提供了訪問項目的選擇 – charlietfl
我我正在使用http://twitter.github.io/typeahead.js/ – tomekfranek