【发布时间】:2020-08-09 19:24:09
【问题描述】:
我已经设置了一个带有 Bloodhound 和 tagsinput 的自动完成搜索表单。
它在远程中运行良好,但使用 Wordpress API 显示建议大约需要 1 或 2 秒。
我想在输入中添加一个加载微调器。这样一来,人们就会清楚他们必须等待建议加载。
我知道这篇文章https://github.com/twitter/typeahead.js/issues/166,但它只是关于 typeaheadjs 而不是 tagsinput。而且老实说,我在使用 Bloodhound 和 tagsinput 时不太了解 typeaheadjs 的用途。
我使用 2 个 js 文件:typeahead.bundle.js 和 bootstrap-tagsinput.js
这是我的工作代码(没有微调器):
var transform_terms = function( terms ) {
return $.map( terms, function( term ) {
return {
id: term.id,
name: term.name,
count: term.count
};
} );
};
var localisations = new Bloodhound( {
datumTokenizer: Bloodhound.tokenizers.obj.whitespace( [ 'name', 'id' ] ),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function( term ) {
return {
label: term.name,
value: term.id,
};
},
sufficient: 5,
remote: {
url: '/wp-json/wp/v2/localisation?_fields=name,id&orderby=count&order=desc&hide_empty=false&search=%QUERY',
wildcard: '%QUERY',
transform: transform_terms
},
indexRemote: true
} );
localisations.initialize();
$('#localisation').tagsinput({
itemValue: 'id',
itemText: 'name',
maxTags: 5,
confirmKeys: [13, 9],
typeaheadjs: {
name: 'localisations',
displayKey: 'name',
source: localisations.ttAdapter()
}
});
谁能帮我在查询过程中添加微调器? 提前非常感谢!
【问题讨论】:
标签: jquery typeahead.js bloodhound bootstrap-tags-input