duanqinjiao5244 2015-07-23 19:44
浏览 62
已采纳

Laravel 5.1 typeahead.js无法找到任何数据

i'm using laravel 5.1 and i try to add some autocomplete into my form, it is not return an error but it's always return unable to find any. i'm very new in javascript. please help me to fix it

here is my template:

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

here is my route :

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

here is my controller

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);
    }

}

here is my 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>'
            ]
        }
    });
});
  • 写回答

1条回答 默认 最新

  • dongweng6241 2015-07-23 21:02
    关注

    Can I suggest another autocomplete javascript library. How about SELECT2. here is the link. https://select2.github.io/examples.html . it's easy to implement. I used typeahead before and it took me a day or two to get it work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流