gpt4 book ai didi

javascript - 获取后映射预输入建议

转载 作者:行者123 更新时间:2023-11-30 05:38:48 25 4
gpt4 key购买 nike

我正在使用上次推特提前输入。

var suggestions = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {url:'/xxx?text=%QUERY',
ajax:{
type : 'post',
dataType : 'json'
}
}
});
suggestions.initialize();

$('.typeahead').typeahead(null, {
displayKey: 'id',
source: suggestions.ttAdapter(),
templates: {
empty: '<p style="width:50%;margin:auto;">No result</p>',
suggestion: function(object){
var str = ['<p>',
object.id,
'</p><a class="btn btn-info btn-small" href="item.html?id="',
object.id,
'>Open</a>'].join('');

return str;
}
}
});

问题是我收到了 5 个类型的对象

{
id: 0,
field: '',
value: ''
}

所有 5 个对象具有相同的 ID,因此是一个结果的字段,应该放入一个建议。 Typeahead 将它们视为单独的建议我不想要

我如何映射 ajax 调用的结果,对其进行转换并将结果传回 typeahead?

最佳答案

您可以使用 filter(parsedResponse)自己解析响应。你可以看到一个例子(一个不相关的答案)here .

关于javascript - 获取后映射预输入建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22014126/

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