UI Bootstrap typeahead拒绝迭代对象

时间:2013-07-27 00:16:51

标签: angularjs angular-ui-bootstrap

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

但不幸的是,似乎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-Bootstrap的ui-bootstrap-tpls-0.4.0.js需要进行编辑(在2749行附近)以允许这种功能

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

谢谢,

1 个答案:

答案 0 :(得分:3)

实际上,来自http://angular-ui.github.io/bootstrap/的typeahead指令的当前实现仅适用于作为数组的源,因此无法迭代对象。我在文件中打开了一个问题来澄清这个问题:
https://github.com/angular-ui/bootstrap/issues/715

罪魁祸首就是这段代码,真的: https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js#L109-L115

虽然将其切换到angular.forEach会使情况更好,但主要问题是内置的AngularJS过滤器无法在对象上运行...所以你必须编写自己的匹配逻辑。这就是为什么我决定放弃对(key, value)语法的支持。

目前您最好的选择是将对象转换为数组

因此,我将更新文档以明确支持哪些内容以及哪些内容不受支持。但如果您能在这里看到完美的解决方案,请随时发送拉动请求!

相关问题