如何使用预输入通配符
How to use typeahead wildcard
我是第一次尝试使用提前输入。我想根据用户输入更新 url 参数。未翻译通配符,值 "QUERY" 正在发送到远程服务器。
任何帮助将不胜感激:)
myTypeahead = $('.typeahead').typeahead(
{
hint: true,
highlight: true,
minLength: 1
},
{
name: 'addresses',
source: addressResults = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url:'https://urlpath/Search?query=%QUERY&country=GBR',
wildcard: '%QUERY',
filter: function (data) {
// Map the remote source JSON array to a JavaScript object array
return $.map(data.results, function(results,index) {
return results.suggestion;
});
},
prepare: function (query, settings) {
settings.headers = {
'Auth-Token' : '1212'
};
return settings;
}
}
})
}
).on('keyup');
当您使用prepare
时,您需要手动处理通配符值。见 documentation for remote
例如:
prepare: function(query, settings) {
settings.url += '?q=' + query;
return settings;
},
这里是 associated fiddle.
我是第一次尝试使用提前输入。我想根据用户输入更新 url 参数。未翻译通配符,值 "QUERY" 正在发送到远程服务器。
任何帮助将不胜感激:)
myTypeahead = $('.typeahead').typeahead(
{
hint: true,
highlight: true,
minLength: 1
},
{
name: 'addresses',
source: addressResults = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url:'https://urlpath/Search?query=%QUERY&country=GBR',
wildcard: '%QUERY',
filter: function (data) {
// Map the remote source JSON array to a JavaScript object array
return $.map(data.results, function(results,index) {
return results.suggestion;
});
},
prepare: function (query, settings) {
settings.headers = {
'Auth-Token' : '1212'
};
return settings;
}
}
})
}
).on('keyup');
当您使用prepare
时,您需要手动处理通配符值。见 documentation for remote
例如:
prepare: function(query, settings) {
settings.url += '?q=' + query;
return settings;
},
这里是 associated fiddle.