【问题标题】:Angular Bootstrap Type Ahead Issues with typeahead syntaxAngular Bootstrap Type Ahead 与 typeahead 语法有关的问题
【发布时间】:2014-03-14 08:20:33
【问题描述】:

我在这里一直使用 type ahead 指令,效果很好: 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

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

【问题讨论】:

    标签: angularjs angular-ui-bootstrap typeahead


    【解决方案1】:

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

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

    【讨论】:

    • 你在这个问题上完全救了我,感谢您发布您的解决方案。它还使我朝着正确的方向前进,以从 angular-ui 开发人员那里了解有关此问题的更多信息。请参阅 pkozlowski-opensource github.com/angular-ui/bootstrap/issues/981 和他的 plunkr 的回复。它使用typeahead-input-formatter 属性。
    猜你喜欢
    • 2012-11-18
    • 2019-10-20
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多