如何使用 ngRepeat 将 angularFire 对象排序为 orderBy? [英] How do I get angularFire objects to orderBy with ngRepeat?
问题描述
我的 firebase 中的当前数据集如下所示:
The current bunch of data in my firebase looks something like:
{"-JZ7b":{"name":"bob","has":"slack"},"-JZ7a":{"name":"connie","has":"slack"}}
如果我使用类似的东西:
If I use something like:
<ul><li ng-repeat="(key, person) in people |orderBy 'name'"></li></ul>
我明白了:
- -JZ7a 康妮有懈怠
- -JZ7b 鲍勃有松弛
获得预期订单的最佳方法是什么而不将我的数据更改为其他格式?我意识到在这个例子中,键并不完全有意义,但假设它们是.构建自定义指令的想法似乎是一个有趣的选择,但是,与原始代码相比,我的代码可能有点刺耳.
What is the best way to get the expected orderBy without changing my data into some other format? I realize that in this example the keys aren't exactly meaningful but, assume they are. The idea of a building a custom directive seems like an interesting option but, my code can be a bit jangly compared to the original.
推荐答案
OrderBy 不适用于对象.您可以使用过滤器 toArray.
OrderBy doesn't apply to objects. You can use the filter toArray.
<li ng-repeat="p in people | toArray | orderBy: 'name'" ng-click="cpSelect(p.$key)">
{{p.$key}} {{p.name}} has {{p.has}}
</li>
这篇关于如何使用 ngRepeat 将 angularFire 对象排序为 orderBy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!