1

私はかなり前から Twitter の先行入力を使用してきましたが、これは私のリモート データにとって非常に簡単で便利です。ここで、堅牢なブラッドハウンド エンジンを使用できるように、最新バージョン (typeahead.js 0.10.5) にアップグレードすることにしました。私はブラッドハウンドにかなりの問題を抱えています.

リンクが正常に機能し、すべての国が表示されるためurl、私が呼び出している は正しいと思います。私が変更prefetchした唯一のことは、どちらでもremote機能しませんprefetch。また、スタックエクスチェンジで他の例を試してみましたが、ヘッダーでスクリプトを正しく呼び出していることを示唆していますが、Twitter が提供する URL に変更すると機能しません。twitter-typeahead の例からコピーしたコードを正しく使用しているかどうかを知りたいです。

    <div id="prefetch">
      <input class="typeahead" type="text" placeholder="Countries">
    </div>
<script type='text/javascript'>
$(function() {
   var countries = new Bloodhound({
      datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),       
      queryTokenizer: Bloodhound.tokenizers.whitespace,
      limit: 10,
      remote: {
        // url points to a json file that contains an array of country names, see
        // https://github.com/twitter/typeahead.js/blob/gh-pages/data/countries.json
        url: 'https://github.com/twitter/typeahead.js/blob/gh-pages/data/countries.json',
        // the json file contains an array of strings, but the Bloodhound
        // suggestion engine expects JavaScript objects so this converts all of
        // those strings
        filter: function (list) {
          return $.map(list, function (country) { 
            return { 
                name: country 
                }; 
            });
        }
      }
    });

    // kicks off the loading/processing of `local` and `prefetch`
    countries.initialize();

    // passing in `null` for the `options` arguments will result in the default
    // options being used
    $('#prefetch .typeahead').typeahead(null, {
      name: 'countries',
      displayKey: 'name',
      // `ttAdapter` wraps the suggestion engine in an adapter that
      // is compatible with the typeahead jQuery plugin
      source: countries.ttAdapter()
    });
});
</script>
4

0 に答える 0