2015-11-01 5 views
0

Может ли кто-нибудь мне помочь? У меня есть формаtypeahead возвращает только первые 5 строк базы данных

<form action={{'/query'}} method="get" autocomplete="off"> 
     <input type="text" name="places" id="places"> 
     <input type="submit" value="Go"> 
</form> 

это мой 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() 

}); 

});

это мой маршрут

Route::get('/query',['uses'=>[email protected]]); 

это функция запроса в HomeController

public function query() 
{ 

    $query = Input::get('places'); 
    $results = DB::table('evac_center')->where('name','LIKE',$query.'%')->get(); 

    return Response::json($results); 
} 

это результат result

Проблемы все, что я печатаю в поле ввода в машинописном будет возвращать только первые 5 строк из моей базы данных.

ответ

0

limit Попробуйте установить в параметрах набора данных:

$('#places').typeahead({ 
    hint:true, 
    highLight: true, 
    minLength:2 
    },{ 
    name:'places', 
    displayKey: 'name', 
    limit: 25, 
    source: places.ttAdapter() 
    }); 

Вы можете также установить sufficient в ваших Bloodhound опций:

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

Смежные вопросы