簡體   English   中英

Laravel 5.1 typeahead.js無法找到任何數據

[英]Laravel 5.1 typeahead.js unable to find any data

我正在使用laravel 5.1,我嘗試將一些自動完成功能添加到表單中,它不會返回錯誤,但始終會返回無法找到的任何內容。 我在javascript中非常新。 請幫我解決

這是我的模板:

{!! Form::label('Name', 'Name:') !!}
{!! Form::text('name',null,['class'=>'form-control', 'id'=>'users']) !!}

這是我的路線:

Route::get('/', 'SearchController@index');
Route::get('/query','SearchController@query');

這是我的控制器

class SearchController extends Controller {

    public function index() {
        return View::make('template');
    }

    public function query() {
        $query = Input::get('name');
        $res = User::where('name', 'LIKE', "%$query%")->get();
        return Response::json($res);
    }

}

這是我的main.js

jQuery(document).ready(function($) {
    var sugest = new Bloodhound({
        remote: '/bookstore/query?name=%QUERY%',
        // '...' = displayKey: '...'
        datumTokenizer: Bloodhound.tokenizers.whitespace('name'),
        queryTokenizer: Bloodhound.tokenizers.whitespace
    });

    sugest.initialize();

    $("#users").typeahead({
        hint: true,
        highlight: true,
        minLength: 2
    }, {
        source: sugest.ttAdapter(),
        name: 'engine',
        displayKey: 'name',
        templates: {
            empty: [
                '<div class="empty-message">unable to find any</div>'
            ]
        }
    });
});

我可以建議另一個自動完成的JavaScript庫。 SELECT2怎么樣。 鏈接在這里。 https://select2.github.io/examples.html 這很容易實現。 我以前用過typeahead,花了我一兩天的時間才能開始工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM