1

I am new to working on Typeahead and Bloodhound and i'am using latest js. Below is my sample code. Html:

<div id="multiple-datasets">
    <input class="typeahead" type="text" placeholder="NBA and NHL teams">
</div>

Here is the script:

var nbaTeams = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        prefetch: '{ "names": ["Aaron  Kreisler","Adam  Alder","Adam  Preece"]}'
      });

   var nhlTeams = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        prefetch: '{ "titles": ["Acute Chronic Pancreatitis Program", "Aerodigestive Program", "Analytical Imaging and Modeling Center (AIM)"]}'

      });

  $('#multiple-datasets .typeahead').typeahead({           
        highlight: true
      },
      {
        name: 'nba-teams',
        display: 'team',
        source: nbaTeams,
        templates: {
          header: '<h3 class="league-name">NBA Teams</h3>'
        }
      },
      {
        name: 'nhl-teams',
        display: 'team',
        source: nhlTeams,
        templates: {
          header: '<h3 class="league-name">NHL Teams</h3>'
        }
 });

Any help. Thank you!

Medoju Narendar
  • 185
  • 1
  • 4
  • 18

2 Answers2

0

bloodhound multiple dataset cause typeahead template issue

I post a question about that too (link on top), but I'v multiple dataset working, just the templates part broken. It's the code from officials examples but without the json file, can you post it on a jsfiddle.net

Community
  • 1
  • 1
Nicolas
  • 571
  • 6
  • 13
0

display property seems to be wrong (blind c&p issue?); as given in doc display should point to the data-field within each matching data-row

Pls try the edited code-block below:

var nbaTeams = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: ["Aaron  Kreisler","Adam  Alder","Adam  Preece"]
  });

var nhlTeams = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: ["Acute Chronic Pancreatitis Program", "Aerodigestive Program", "Analytical Imaging and Modeling Center (AIM)"]
  });

$('#multiple-datasets .typeahead').typeahead({           
    highlight: true
  },
  {
    name: 'nba-teams',
    source: nbaTeams,
    templates: {
      header: '<h3 class="league-name">NBA Teams</h3>'
    }
  },
  {
    name: 'nhl-teams',
    source: nhlTeams,
    templates: {
      header: '<h3 class="league-name">NHL Teams</h3>'
    }
 });
Joshua Baboo
  • 525
  • 1
  • 4
  • 17