【发布时间】:2012-08-25 08:34:26
【问题描述】:
假设我想在原来的 bootstrap-typeahead.js 中添加一些功能。
我不喜欢分叉另一个库然后对其进行编辑以添加功能或使用分叉库的想法。
一个用例可能是:将选项 onselect 添加到 $.fn.typeahead.defaults 以便在我选择自动完成中的项目时执行回调。
这是我的测试(1),请添加 cmets 和代码使其工作。
(1)
_.extend($.fn.typeahead.defaults, {onselect: null});
element.typeahead({
minLength: 3,
source: function () {
return ['val1', 'val2'];
},
onselect: function (val) {
console.log(val); // it should be able to get the value selected
}
});
【问题讨论】:
标签: javascript jquery autocomplete twitter-bootstrap