Jes*_*sse 14 angularjs bootstrap-typeahead angular-ui-bootstrap
我正在尝试设置typeahead使用AngularJS和UI Bootstrap,如下所示:
html的
<input type="text" ng-model="selectedStuff" typeahead="stuff.name for stuff in stuffs | filter:$viewValue"/>
<span>{{selectedStuff.name}}</span>
<span>{{selectedStuff.desc}}</span>
Run Code Online (Sandbox Code Playgroud)
.js文件
$scope.stuffs= [
{
"name":"thing1",
"desc":"this is the first thing"
},
{
"name":"thing2",
"desc":"this is the second thing"
}
]
Run Code Online (Sandbox Code Playgroud)
目前,我已经能够使用所选名称更新模型,但我的目标是通过传递整个对象typeahead.有没有一种干净的方法只使用输入?
pko*_*rce 26
当然可以:-)
从预输入指令http://angular-ui.github.io/bootstrap/使用相同的超灵活的语法为AngularJS 选择指令进行ng-options.所以你可以写:
typeahead="stuff as stuff.name for stuff in stuffs | filter:$viewValue"
Run Code Online (Sandbox Code Playgroud)
这是一个有效的插件:http://plnkr.co/edit/5kGZkNPZ7rIFfb4Rvxej?p = preview
| 归档时间: |
|
| 查看次数: |
10451 次 |
| 最近记录: |