【问题标题】:typeahead returns only the first 5 rows of the databasetypeahead 仅返回数据库的前 5 行
【发布时间】:2016-02-01 12:45:57
【问题描述】:

谁能帮我解决这个问题? 我有一个表格

 <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'=>HomeController@query]);

这是 HomeController 中的查询函数

public function query()
{

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

    return Response::json($results);
}

这是结果 result

问题是我在输入框中输入的任何内容,typeahead 只会返回我数据库中的前 5 行。

【问题讨论】:

    标签: javascript json laravel-4 typeahead.js


    【解决方案1】:

    尝试在您的数据集选项中设置limit

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

    您可能还需要在 Bloodhound 选项中设置 sufficient

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多