我正在尝试使用Twitter typeahead.js在选择后返回数据。根据我对文档的了解,代码应该看起来像

$('.selector').typeahead({
  name: 'identifier',
  local: localObjectsArray
}).on('autocompleted', function(item){
    alert(JSON.stringify(item));
});


但是,这不起作用。检测提前事件的正确方法是什么?

最佳答案

选择之后,因此您需要typeahead:selected

$('.selector').typeahead({
    name: 'identifier',
    local: localObjectsArray
}).on('typeahead:selected', function (obj, datum) {
    console.log(obj);
    console.log(datum);
});


希望能帮助到你。

10-05 21:03
查看更多