1
我正在使用railscasts tokeninput插件自动完成。我想,只有在下拉列表中显示的项,其是不包含在输入字段相同的项目列表未来railscasts tokeninput
我的JS代码是
$(function() {
$("#category").tokenInput("/products/product_categories.json", {
crossDomain: false,
prePopulate: $("#category").data("pre"),
theme: "facebook"
});
});
我控制器
def product_categories
category = Category.where("name like ?", "%#{params[:q]}%")
respond_to do |format|
format.html
format.json { render :json => category.map(&:attributes) }
end
末
它工作正常但问题是每次出现同样的列表。假设在dropdwon列表中有两个条目亚洲和非洲。亚洲加入输入字段后,再次点击字段时亚洲和非洲出现。
我想,如果条目已经包含在输入字段它不能出现在下拉列表中
Cna你分享一些信息如何使用preventDuplicates? –
请参阅http://stackoverflow.com/questions/24699683/problems-with-the-jquery-plugin-tokeninput –