CI と Typeahead に問題があり、結果が得られません ;/
JS
var countries = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.name); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: {
url: base_url + 'home/search?q=%QUERY',
filter: function(list) {
return $.map(list, function(country) { return { name: country }; });
}
}
});
countries.initialize();
$('.typeahead').typeahead(null, {
name: 'countries',
displayKey: 'name',
source: countries.ttAdapter()
});
CI コントローラー
public function search(){
$query = $this->home_model->getData();
echo json_encode($query);
}
CI モデル
private $_cityTable = 'city';
public function getData(){
$city = $this->input->get('q');
$query = $this->db->select('city_name')->like('city_name', $city, 'after')->get($this->_cityTable);
foreach ($query->result_array as $key) {
$array[] = $key['city_name'];
}
return $array;
}
そして見る
<input type="text" class="typeahead">
誰かがこの問題を解決するのを手伝ってくれますか?