title: Bootstrap typeahead, change the datasource used by the bloodhound suggestion engine
body: <p>I've a search field with autocomplete that is initialized like this:</p>
  
  <pre><code>    var reposVenda = new Bloodhound({
      datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.bairro); },
      queryTokenizer: Bloodhound.tokenizers.whitespace,
      prefetch: {
          url: urlAutoCompleteVenda
      }
  });
  
  var reposAluguel = new Bloodhound({
      datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.bairro); },
      queryTokenizer: Bloodhound.tokenizers.whitespace,
      prefetch: {
          url: urlAutoCompleteAluguel
      }
  });
  
  reposVenda.initialize();
  reposAluguel.initialize();
  
  $('#searchQuery').typeahead(null, {
      name: 'bairros',
      displayKey: 'bairro',
      source: reposVenda.ttAdapter(),
      templates: {
          suggestion: Handlebars.compile([
            '&lt;p class="bairro-autocomplete"&gt;{{bairro}}&lt;/p&gt;'
          ].join(''))
      },
      queryTokenizer: queryTokenizer
  });
  </code></pre>
  
  <p>Now I need to change the source when user clicks a button on the page:</p>
  
  <pre><code>    $(".opt-busca-home").click(function (e) {
      e.preventDefault();
  
      var idItem = $(this).attr("id");
      buscaAtual = idItem.replace("opt-", "");
  
      if (buscaAtual == "comprar") {
          var autocomplete = $('#searchQuery').typeahead();
          autocomplete.data('typeahead').source = reposVenda.ttAdapter();
      }
      else {
          var autocomplete = $('#searchQuery').typeahead();
          autocomplete.data('typeahead').source = reposAluguel.ttAdapter();
      }
  });
  </code></pre>
  
  <p>The problem is when I click the button to change the source the console tells me  'Uncaught TypeError: Cannot set property 'source' of undefined'</p>
  
  <p>I tried every possible approach without success. The typeahead works but only with the initialized source. What I'm doing wrong?</p>