键入预 JS "remote is always used"



我知道只有当预取结果不超过设置的限制时,才应使用远程。 我已将限制设置为 1,并且预取有多个条目。它仍然使用远程来获取数据,最终仅显示 1 个结果。

initialise_quick_search: function () {
var building_data = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('building_name'),
queryTokenizer: Bloodhound.tokenizers.nonword,
prefetch: {
url: '/quick_search/quick_search_results?search_buildings=1',
//cache: false
},
remote: {
url: '/quick_search/quick_search_results?search_buildings=1&query=%QUERY',
wildcard: '%QUERY',
cache: false
}
});
building_data.initialize();

var $quick_search = $('#quick_search');
$quick_search.typeahead({
highlight: true,
hint: false,
minLength: 2,
},
{
name: 'buildings',
display: 'building_name',
source: building_data,
limit: 1,
templates: {
header: 'Buildings',
suggestion: function (data) {
return '<p><a target="_blank" href=' + data.href + '>' + data.text + '</a></p>'
}
}
}
);
$quick_search.bind('typeahead:close', function (ev, suggestion) {
$quick_search.val('');
$quick_search.typeahead('close');
});
$quick_search.bind('typeahead:select', function (ev, suggestion) {
window.open(suggestion.href, '_blank');
});
}

如果有人希望在预取中至少有一个条目时不触发远程,请在 typeahead.bundle 文件中更改以下代码片段中的足够值.js

var oParser = function() {
"use strict";
return function parse(o) {
var defaults, sorter;
defaults = {
initialize: true,
identify: _.stringify,
datumTokenizer: null,
queryTokenizer: null,
matchAnyQueryToken: false,
sufficient: 5,
indexRemote: false,
sorter: null,
local: [],
prefetch: null,
remote: null

相关内容

  • 没有找到相关文章

最新更新