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 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决