3

根据官方 ui-bootstrap 上的文档,typeahead 指令“使用与select 指令相同、灵活的语法”

但不幸的是,typeahead 指令似乎拒绝使用以下支持的语法列表遍历对象源select

for object data sources:

label for (key , value) in object
select as label for (key , value) in object
label group by group for (key, value) in object
select as label group by group for (key, value) in object

我认为 UI-Bootstrapui-bootstrap-tpls-0.4.0.js需要进行编辑(在 line 附近2749)以允许这种功能

所以我的问题是实现这个功能的角度和 ui-bootstrap 友好的方法是什么,(我可以通过用.length更对象友好的东西替换来做到这一点,但我想有更多更好的方法来支持select对象数据源语法,我无法提供)

谢谢,

4

1 回答 1

3

Indeed, the current implementation of the typeahead directive from http://angular-ui.github.io/bootstrap/ works only on sources that are arrays, so there is no way to iterate over objects. I've opened an issue to clarify this in the documentation:
https://github.com/angular-ui/bootstrap/issues/715

The culprit is this piece of code, really: https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js#L109-L115

While switching it to the angular.forEach would make the situation better, the main problem is that built-in AngularJS filters won't work on objects... So you would have to write your own matching logic as well. This is why I've decided to drop support for the (key, value) syntax.

Currently your best option is to convert your object to an array.

So I'm going to update the docs to make it clear what is supported and what is not. But if you can see a perfect solution here, feel free to send a pull request!

于 2013-07-27T08:23:14.200 回答