使用: typeahead.js 0.11.1 (typeaheadbundle.js)
我正在尝试使用探犬来预取多个结果组,并根据结果组选择返回它们。无需分组(只需提供URL),代码就可以完美地工作。当我尝试通过使用prepare进行预取来添加分组时,没有调用prepare函数。
有效的代码(仅限URL预取):
var suggestionUniverse = new Bloodhound({
initialize: false,
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('Value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch:'./suggestlist.json'
});
var promise = suggestionUniverse.initialize(true);//initialize and clear any existing cache.
promise.fail(function () { console.log('err, something went wrong :('); });不起作用的代码(使用prepare预取):
var suggestionUniverse= new Bloodhound({
initialize: false,
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('Value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch:{
url: './suggestlist.json',
prepare: function (settings) {
console.log("Called prepare");
return settings; //Optional: Add filter for batchid?
},
transform: function(response) {
console.log("Called transform");
return response;//add batch filters needed to reduce response.
}
}
});
var promise = suggestionUniverse.initialize(true);//initialize and clear any existing cache.
promise.fail(function () { console.log('err, something went wrong :('); });我在控制台中看不到任何消息,无论是在初始化期间(好,没有错误),还是在建议显示期间(不好,没有调用准备或转换)。我是不是漏掉了什么?
发布于 2018-02-08 19:53:56
检查您的调试器工具,查看是否正在向“./suggestlist.json”发出请求,以及请求是否成功。我遇到了类似的问题,并且意识到我的预取被缓存了,所以永远不会调用准备和转换函数。尝试将'cache: false‘添加到预取设置(如果需要,如果它开始工作,则将其删除)。
https://stackoverflow.com/questions/48551196
复制相似问题