angularjs - Angular Bootstrap Type Ahead 与 typeahead 语法相关的问题

标签 angularjs angular-ui-bootstrap typeahead

我一直在这里使用 type advance 指令,效果很好: http://angular-ui.github.io/bootstrap/#/typeahead

我的问题是,我已经摆脱了使用整个对象的场景:

<input type="text" ng-model="MyPerson" typeahead="i as i.Name for i in PeopleSearch($viewValue)" />

对于我只想要对象的一部分的场景:

<input type="text" ng-model="MyPerson" typeahead="i.Id as i.Name for i in PeopleSearch($viewValue)" />

此时,无论为“as”输入什么,模型和文本框都将包含相同的内容。谁能解释为什么会发生这种情况?看起来逻辑应该模仿 ng-options 的表达式,但显然事实并非如此。

这是一个演示:http://plnkr.co/edit/5oqlldC3PltnrynqhnAU?p=preview

选择项目后,文本框应包含此人的姓名。

最佳答案

这是我的解决方案,以防其他人遇到这种情况:

<input type="text" ng-model="MySelectedPerson" typeahead="i as i.Name for i in PeopleSearch($viewValue)" typeahead-on-select="MyPerson = MySelectedPerson.Id" />

关于angularjs - Angular Bootstrap Type Ahead 与 typeahead 语法相关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21788397/

相关文章:

javascript - Bootstrap 行/列默认不折叠?

AngularJS [typeahead] 在 onFocus 上重新打开结果下拉列表

javascript - Bootstrap Typeahead 转义?

twitter-bootstrap - Twitter Bootstrap typeahead 和 jQuery Validate

javascript - Angular指令充当其他元素的外观的好方法是什么?

angularjs - 如何在 YouTube 中获取当前搜索位置?

angularjs - 可点击面板内的可点击按钮

javascript - 如何在 Angular UI typeahead 中正确使用 select 和 firebase 数据

AngularJS 可选 ng-transinclude

angularjs - 如何在 ionic 中制作圆形输入字段?