Typeahead JS自定义事件未触发

问题描述 投票:1回答:1

我正在尝试触发自定义事件,例如:

typeahead:select,但没有任何反应。

我的代码列出了我想要的信息,但是当我什么也没选择时。

我在做什么错?

var route = "autocomplete";
$('.clientName').typeahead({
    minLength: 1,
    highlight: true,
    source:  function (term, process) {
      return $.get(route, { term: term }, function (data) {
            return process(data);
        });
    }

});

$('.clientName').on('typeahead:select', function(ev, suggestion) {
  alert("here");
  console.log('Selection: ' + suggestion);

});

javascript laravel typeahead
1个回答
0
投票

您需要在此处将typeahead:select更改为typeahead:selected

$('.clientName').on('typeahead:selected', function(ev, suggestion) {
  alert("here");
  console.log('Selection: ' + suggestion);

OR

$('.clientName').bind('typeahead:selected', function(ev, suggestion) {
  alert("here");
  console.log('Selection: ' + suggestion);
© www.soinside.com 2019 - 2024. All rights reserved.