0

I already tried the solution in : Typeahead shows not all items from json but didn't work for me, so sorry if duplicate, but I cannot find a way to properly fix it.

I use Bloodhound and Typeahead to retrieve from a php file a list of formulas. As an exemple if I write in the search bar: "scorul A" the list provided by the php file is:

[
    {
        "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"
    ]
}

]

But the search only displays first result. If I write "scorul AT" than the other appear, but if not they don't appear.

I cannot understand why. Here is the typeahead script in the page:

$(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');
});
});
Community
  • 1
  • 1
  • Hey, could you try the solution I outlined in this post: http://stackoverflow.com/questions/33436961/twitter-typeahead-remote-not-completing-some-queries/33438444#33438444 – Andy Noelker Dec 27 '15 at 14:54
  • It's similar to the linked solution that you tried, only it involves moving that line rather than deleting it. You might be experiencing the same bug. Please let me know your results. – Andy Noelker Dec 27 '15 at 14:55
  • I tried it right now. Cleared cache. Still the same. – Andone Sebastian Dec 27 '15 at 15:03
  • Also I saw a very weird mechanic when I remove the prefetch. It shows even fewer results than without the prefetch. – Andone Sebastian Dec 27 '15 at 15:06
  • Hmm okay, just wanted to check and see if it could be solved that simply :) Unfortunately typeahead is an abandoned project. I know there is a community maintained version that might resolve your problem if you wanted to use that instead: https://github.com/corejavascript/typeahead.js – Andy Noelker Dec 27 '15 at 15:12

0 Answers0