我已经在Typeahead shows not all items from json尝试了解决方案,但是对我来说不起作用,如果重复,我很抱歉,但我找不到正确修复它的方法。
我使用Bloodhound和Typeahead从php文件中检索公式列表。 作为一个例子,如果我在搜索栏中写道:“scorul A”,php文件提供的列表是:
[
{
"name": "Scorul ABC pentru transfuzia sanguina masiva",
"description": "Scorul prezice necesitatea unei transfuzii sanguine masive la pacientii traumatizati.",
"category": "Anestezie si terapie intensiva/Medicina de Urgenta/Trauma",
"value": "Scorul ABC pentru transfuzia sanguina masiva",
"id": "20",
"extra": "",
"tokens": [
"Scorul",
"ABC",
"pentru",
"transfuzia",
"sanguina",
"masiva"
]
},
{
"name": "Scorul ATRIA pentru evaluarea riscului de sangerare",
"description": "Evalueaza riscul de sangerare la pacientii la care se administreaza Warfarina.",
"category": "Cardiologie/Neurologie",
"value": "Scorul ATRIA pentru evaluarea riscului de sangerare",
"id": "21",
"extra": "",
"tokens": [
"Scorul",
"ATRIA",
"pentru",
"evaluarea",
"riscului",
"de",
"sangerare"
]
},
{
"name": "Scorul ATRIA pentru evaluarea riscului de accident vascular",
"description": "Evalueaza riscul de accident vascular la pacientii cu fibrilatie atriala.",
"category": "Anestezie si terapie intensiva/Cardiologie/Neurologie",
"value": "Scorul ATRIA pentru evaluarea riscului de accident vascular",
"id": "23",
"extra": "",
"tokens": [
"Scorul",
"ATRIA",
"pentru",
"evaluarea",
"riscului",
"de",
"accident",
"vascular"
]
}
但搜索仅显示第一个结果。 如果我写“scorul AT”而不是其他出现,但如果不是,它们就不会出现。
我无法理解为什么。 以下是页面中的预先输入脚本:
$(document).ready(function() {
var repos;
repos = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: 'repos.php?t=2',
remote:
{
url: 'repos.php?t=1&q=%QUERY',
wildcard: '%QUERY'
}
});
repos.initialize();
$('.typeahead').typeahead(null, {
name: 'repos',
displayKey: 'value',
source: repos.ttAdapter(),
limit: 6,
templates: {
footer : ['<div class="tt-suggestion more-results">',
'<p></p>',
'<div class="repo-name"><i class="fa fa-search"></i> Cautare avansata</div>',
'<p></p>',
'<div>'].join(''),
suggestion: Handlebars.compile([
'<div>',
'<p class="repo-name {{extra}}">{{name}}</p>',
'<p class="repo-description">{{description}}</p>',
'<p class="repo-category">{{category}}</p>',
'</div>'].join(''))}
}).on('typeahead:selected', function (obj, datum) {
datum.name=encodeURIComponent(datum.name);
if(datum.extra!='repo-folder')
window.location.replace('formule.php?t='+datum.name+'&f='+datum.id+'&p=5');
else
window.location.replace('formule.php?t='+datum.name+'&c='+datum.id+'&p=4');
});
});