Javascript Rails:typeahead.js下拉列表返回已删除的重复项或对象
我已经在我的rails应用程序上安装了Javascript Rails:typeahead.js下拉列表返回已删除的重复项或对象,javascript,ruby-on-rails,typeahead.js,typeahead,Javascript,Ruby On Rails,Typeahead.js,Typeahead,我已经在我的rails应用程序上安装了typeahead.js,但是当我开始在输入字段中键入一个单词时,下拉列表会返回已删除的重复项或对象以及正确的单词 这是我的设置: 控制器内部: def autocomplete render json: Item.search(params[:search], { fields: ["title"], match: :word_start, limit: 10, load: false, misspellings:
typeahead.js
,但是当我开始在输入字段中键入一个单词时,下拉列表会返回已删除的重复项或对象以及正确的单词
这是我的设置:
控制器内部:
def autocomplete
render json: Item.search(params[:search], {
fields: ["title"],
match: :word_start,
limit: 10,
load: false,
misspellings: {below: 5}
}).map(&:title).uniq
end
在视图内部:
<script>
var items = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/items/autocomplete?search=%SEARCH',
wildcard: '%SEARCH'
}
});
$('#search')
.typeahead(null, {source: items})
.on('typeahead:selected', function(e){
$("#search-form").submit();
}).focus();
</script>
您的API的响应是什么?检查浏览器的“网络”选项卡。回复中是否有重复/删除的条目?感谢@Ash回复,实际上没有,它没有任何重复/删除的条目!酷。我只是想排除这是服务器端的问题。
2.4.0 :026 > Item.all.map(&:title).uniq
Item Load (0.4ms) SELECT "items".* FROM "items"
=> []