0
ユーザーは都市を指定します。オートコンプリートは、入力された最初の文字で始まります。twitter-typehead-railsで仕事を自動完成しない
"Ber ..."のようにフィールドの最初の文字に入力すると、何も起こりません。
検索とオートコンプリートのためのスクリプトをどのように実行しますか?
私はGemfileで依存関係として宝石をspecifed:
gem 'twitter-typeahead-rails'
application.js
//= require jquery
//= require jquery.turbolinks
//= require underscore
//= require json2
//= require judge
//= require registration
//= require jquery-ui
//= require tag-it
//= require jquery_ujs
//= require chosen
//= require cocoon
//= require jquery-fileupload/basic
//= require twitter/typeahead
//= require freelancers
//= require response
//= require projects
//= require cities_germany
//= require turbolinks
資産/ javascriptの/ cities_germany.js
var cities = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('num'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [{ city: 'Berlin (Berlin)'},
{ city: 'Hamburg (Hamburg)'},
{ city: 'München (Bavaria)'},
{ city: 'Köln (Northrhine-Westfalia)'},
{ city: 'Frankfurt (Hessen)'},
{ city: 'Essen (Northrhine-Westfalia)'},
{ city: 'Dortmund (Northrhine-Westfalia)'},
{ city: 'Stuttgart (Baden-Württemberg)'},
{ city: 'Düsseldorf Northrhine-Westfalia'},
{ city: 'Bremen (Bremen)'},
{ city: 'Hannover (Lower Saxony)'},
{ city: 'Duisburg (Northrhine-Westfalia)'},
{ city: 'Nürnberg (Bavaria)'},
{ city: 'Leipzig (Saxony)'},
{ city: 'Dresden (Saxony)'}
]
});
// initialize the bloodhound suggestion engine
cities.initialize();
$('#main-cities .typeahead').typeahead(null, {
displayKey: 'city',
source: cities.ttAdapter()
});
を私はして追加フォームhtml nex Tフィールド:
<li class="form-fields__group form-fields__group_full">
<%= f.label 'City' %>
<div class="field" id="main-cities">
<%= f.text_field :location, class: 'typeahead' %>
</div>
</li>