twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

Simple use of this library! not really as simple as the 0.9.3 #1425

Open zenithtekla opened 8 years ago

zenithtekla commented 8 years ago

At code.runnable.com with old version 0.9.3 typeahead was easily implemented in a few lines of code. http://code.runnable.com/UlXgeluakNULAAAv/create-an-autocomplete-input-box-with-typeahead-js-for-jquery-and-javascript

  <script type="text/javascript">
    // Waiting for the DOM ready...
    $(function(){
      // applied typeahead to the text input box
      $('#my-input').typeahead({
        name: 'countries',
        // data source
        prefetch: 'data/countries.json',
        // max item numbers list in the dropdown
        limit: 10
      });
    });
  </script>

But the latest version requires more code and effort using Bloodhound... line 1->17 https://github.com/zenithtekla/typeahead/blob/8ff27225f8d047e47e4aa657b7b9a8fe0ed7c63e/experiment/async.js

// Instantiate the Bloodhound suggestion engine
var local = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: {
        url: 'json/countries.json'
    }
}); // filter can be omitted, prefetch must use external url

// Initialize the Bloodhound suggestion engine
local.initialize();

// Instantiate the Typeahead UI
$('#async .typeahead').typeahead(null, {
    displayKey: 'name',
    source: local.ttAdapter()
});

Now tell me why it does have to be this complicated in the latter version? Is it so advanced that it can no longer take the form of simplest implementation?

duzun commented 8 years ago

+1 !

zenithtekla commented 8 years ago

Grabbed old code(from a linked runnable) and tried changing Typeahead library versions (from 0.9.3 to whatever the latest is) in the header. You will see the old form of simple implementation does not work.