我已经做了好几个小时了,我确信我犯了一个愚蠢的错误。但是我很茫然……
这是我检查过的内容:
文档:
计算器:
示例/谷歌/等 ...
这是我的设置。我有一个 mongoDB,我用 mongoose / Node.js 创建了一个 API 搜索路径。我已验证搜索 API 工作正常。
HTML(哈巴狗)
.answer-container
form(method="POST" enctype="multipart/form-data")#answer-form.form
label(for="new-answer") Answer:
input(required minlength="1" maxlength="80" type="text" name="new-answer" id="new-answer" placeholder="Answer Text" autocomplete="off").new-answer-input
br
input(type="submit" name="submit" disabled autocomplete="off" value="Submit")#answer-submit-button
.answer-messages
我已经确认 pug 模板按预期工作。
JS(提前输入和猎犬)
var answer_suggestions = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace("text"),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote:{
url: 'http://localhost:3000/api/v1/answers/search?text=%QUERY',
wildcard: '%QUERY'
}
});
$('#new-answer').typeahead({
hint: true,
highlight: true,
autoselect: true,
minLength: 2
},
{
name: 'answers',
source: answer_suggestions,
display: 'text',
limit: 10
});
问题 如果我删除
display
选项,我可以看到结果来自 API,并且一切正常。如果我包括它,我得不到任何结果。
[
{
"_id": "64401c91bc76fdfca320c118",
"text": "pneumothorax",
"__v": 0
},
{
"_id": "64403bb708645fb7abbe2db3",
"text": "pneumothorax",
"__v": 0
},
{
"_id": "64403bdf08645fb7abbe2dbf",
"text": "hemopneumothorax",
"__v": 0
}
]
我尝试将数据重构为 json 对象,我尝试使用
display
中的函数,但似乎没有任何效果。
我想要的只是结果列表来简单地显示答案文本。