使用 typeahead,我尝试设置几个选项,这些选项可作为标准 Bootstrap 使用预输入选项 http://twitter.github.io/bootstrap/javascript.html#typeahead
使用以下代码,我可以通过将其内联为“typeahead-min-length”来设置“minLength”属性,但对“items”执行与“typeahead-items”相同的操作则不然。有没有不同/更好/标准的方法来做到这一点?有没有办法将选项数组附加到 $scope ?
<div class='container-fluid' ng-controller="TestController">
<input type="text" ng-model="selected"
typeahead="foo for foo in foo | filter:$viewValue" typeahead-items='5' typeahead-min-length='3'>
<pre>{{selected| json}}</pre> </div>
更新:我试图坚持只使用 AngularJS,而不是使用 jQuery
这是我的控制器:
myAppModule.controller('TestController', function($http,$scope) {
$scope.selected = undefined;
$http.get('data/sample.json')
.then(function(results){
$scope.foo = results.data;
});
});
为什么不使用JS方式来初始化typeahead:
$('input.typeahead').typeahead({
source: array_of_value_here,
minLength: 1,
items: 5,
// your option values ...
});
EDIT:
我明白了,AngularJS 的方式,你可以使用limitTo
:
<input type="text" ng-model="selected" typeahead="foo for foo in foo | filter:$viewValue | limitTo:5" typeahead-min-length='3'>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)