未触发Typeahead JS自定义事件

时间:2019-12-25 02:26:52

标签: javascript laravel typeahead

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

提前输入:选择,但没有任何反应。

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

我在做什么错了?

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

});

1 个答案:

答案 0 :(得分: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);