我对 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">
有人可以帮我解决这个问题吗?