14

我正在尝试设置一个typeahead使用AngularJSUI 引导程序,如下所示:

.html

<input type="text" ng-model="selectedStuff" typeahead="stuff.name for stuff in stuffs | filter:$viewValue"/>

<span>{{selectedStuff.name}}</span>
<span>{{selectedStuff.desc}}</span>

.js

$scope.stuffs= [
                {
                 "name":"thing1",
                 "desc":"this is the first thing"
                },
                {
                 "name":"thing2",
                 "desc":"this is the second thing"
                }
               ]

目前,我已经能够使用所选名称更新模型,但我的目标是通过typeahead. 有没有一种只使用输入的干净方法来做到这一点?

4

2 回答 2

26

肯定的:-)

http://angular-ui.github.io/bootstrap/中的 typeahead 指令使用与 AngularJS选择指令相同的超灵活语法ng-options。所以你可以写:

typeahead="stuff as stuff.name for stuff in stuffs | filter:$viewValue"

这是一个有效的 plunk:http ://plnkr.co/edit/5kGZkNPZ7rIFfb4Rvxej?p=preview

于 2013-04-15T14:48:48.283 回答
0

我有同样的问题。我已经解决了

typeahead="country.name for country in countryList | filter:$viewValue | limitTo:8"

这里 countryList 是国家对象的列表。名称是国家对象的属性之一。对我来说,它工作正常。

于 2015-01-15T19:05:58.440 回答