【发布时间】:2014-01-04 14:58:46
【问题描述】:
我在互联网上搜索,如何将 jQuery UI 自动完成实现到 angularJS 中。我找到了一个很好的样本,它正在工作。这里Sourcecode
HTML
<div ng-app='MyModule'>
<div ng-controller='DefaultCtrl'>
<input auto-complete ui-items="names" ng-model="selected">
selected = {{selected}}
</div>
</div>
JS
function DefaultCtrl($scope) {
$scope.names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];
}
angular.module('MyModule', []).directive('autoComplete', function($timeout) {
return function(scope, iElement, iAttrs) {
iElement.autocomplete({
source: scope[iAttrs.uiItems],
select: function() {
$timeout(function() {
iElement.trigger('input');
}, 0);
}
});
};
});
我真正感到困惑的是,关于 select 事件上的触发输入事件。
select: function() {
$timeout(function() {
iElement.trigger('input');
}, 0);
}
什么是事件的输入,我从未听说过。我在互联网上搜索了有关输入事件的信息,但找不到有用的东西。
【问题讨论】:
-
developer.mozilla.org/en-US/docs/Web/Reference/Events/input 尝试 MDN 文档,注意并非在所有浏览器中都可用
标签: javascript angularjs dom-events