javascript - typeahead returns only the first 5 rows of the database -
can me this? have form
<form action={{'/query'}} method="get" autocomplete="off"> <input type="text" name="places" id="places"> <input type="submit" value="go"> </form>
this searh.js
$(document).ready(function(){ var places = new bloodhound({ datumtokenizer:bloodhound.tokenizers.obj.whitespace('name'), querytokenizer:bloodhound.tokenizers.whitespace, remote: '/query' }); places.initialize(); $('#places').typeahead({ hint:true, highlight: true, minlength:2 },{ name:'places', displaykey: 'name', source: places.ttadapter() });
});
this route
route::get('/query',['uses'=>homecontroller@query]);
this query function in homecontroller
public function query() { $query = input::get('places'); $results = db::table('evac_center')->where('name','like',$query.'%')->get(); return response::json($results); }
this result result
the problem whatever type in input box typeahead return first 5 rows database.
try setting limit
in dataset options:
$('#places').typeahead({ hint:true, highlight: true, minlength:2 },{ name:'places', displaykey: 'name', limit: 25, source: places.ttadapter() });
you may have set sufficient
in bloodhound options:
var places = new bloodhound({ datumtokenizer:bloodhound.tokenizers.obj.whitespace('name'), querytokenizer:bloodhound.tokenizers.whitespace, remote: '/query', sufficient: 25 });
https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md
Comments
Post a Comment