gpt4 book ai didi

javascript - 将 typeahead 从 0.9.3 升级到 0.10.5 远程

转载 作者:行者123 更新时间:2023-12-03 11:38:16 25 4
gpt4 key购买 nike

您好,我在将 typeahead js 从 0.9.3 升级到 0.10.5 时遇到问题。它在 0.9.3 中工作,但我似乎无法让我的远程连接在最新版本中工作。

我正在使用以下代码。

init = function(spec) {
var $field;

$field = $(document.getElementById(spec.id));

var suggestions = new Bloodhound({

datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,

remote: {
url: spec.url,
replace: function(uri, query) {
return extendURL(uri, {
"t:input": query
});
},
filter: function(response) {
return response.matches;
}
}
});

suggestions.initialize();

return $field.typeahead({
limit: 5,
displayKey: 'value',
source: suggestions.ttAdapter()
});
};
return exports = init;

在 0.9.2 中,以下代码有效,但由于某种原因,每次您在输入框中按下按键时,建议都会消失,直到按下匹配项为止。我希望这次升级能够解决我的问题,或者可能是配置问题导致的。

init = function(spec) {
var $field;

$field = $(document.getElementById(spec.id));
return $field.typeahead({
minLength: spec.minChars,
limit: 5,
remote: {
url: spec.url,
replace: function(uri, query) {
return extendURL(uri, {
"t:input": query
});
},
filter: function(response) {
return response.matches;
}
}
});
};

最佳答案

我在构造函数中缺少 null 。

return $field.typeahead({
limit: 5,
displayKey: 'value',
source: suggestions.ttAdapter()
});

修复版本

return $field.typeahead(null, {
minLength: spec.minChars,
displayKey: 'value',
source: suggestions.ttAdapter(),
});

关于javascript - 将 typeahead 从 0.9.3 升级到 0.10.5 远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26386344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com