javascript - 如何提交从 typeahead bloodhound 自动完成填充的数据

标签 javascript bootstrap-typeahead typeahead.js bloodhound

如何提前输入以提交数据。

这里是jsfiddle上的相关代码http://jsfiddle.net/6W3Qu/2/ .

代码副本:

var numbers = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [
{ num: 'one' },
{ num: 'two' },
{ num: 'three' },
{ num: 'four' },
{ num: 'five' },
{ num: 'six' },
{ num: 'seven' },
{ num: 'eight' },
{ num: 'nine' },
{ num: 'ten' }
]
});

// initialize the bloodhound suggestion engine
numbers.initialize();

// instantiate the typeahead UI
$('.typeahead').typeahead(null, {
displayKey: 'num',
source: numbers.ttAdapter(),
updater: function(item) {
    alert(item);
}
});

好像没有进入updater函数

最佳答案

Typeahead.js 没有“更新程序”选项。

相反,您可以编写一个事件处理程序,它将使用 typeahead 的选定事件(即 typeahead:selected),例如

var numSelectedHandler = function (eventObject, suggestionObject, suggestionDataset) {
    alert(suggestionObject.num);
};

typeahead.on('typeahead:selected', numSelectedHandler);

可以在这里找到一个工作示例:

http://jsfiddle.net/Fresh/TXQdy/

关于javascript - 如何提交从 typeahead bloodhound 自动完成填充的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21997266/

相关文章:

jquery - 无法设置未定义的属性 'url'

javascript - 通过拖放将 KnockoutJS 与 JQuery 结合使用

javascript - 如何将 javascript 变量传递到嵌入式 ruby​​ 中?

javascript - Bootstrap 提前输入 : How to get all fetched remote values in typeahead bind function

javascript - Bootstrap Typeahead 在我的场景中只需要点击两次并且需要动态处理 20 行

javascript - 使用数据破折号属性初始化预输入源

javascript - 我怎样才能让 typeahead.js 与 jquery.validate 一起很好地发挥作用?

javascript - document.getElementById 不适用于 Webpack

javascript - Selenium Webdriver 定位器

twitter-bootstrap - 集成 bootstrap-tagsinput、boostrap3-typeahead 和 Bloodhound 的问题