我怎么angularFire对象排序依据与ngRepeat? [英] How do I get angularFire objects to orderBy with ngRepeat?

查看:112
本文介绍了我怎么angularFire对象排序依据与ngRepeat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的火力点数据的当前一堆看起来是这样的:

The current bunch of data in my firebase looks something like:

{ - JZ7b:{名:鲍勃,有:懈怠}, - JZ7a:{名:康妮,具有 松弛}}

如果我用的是这样的:

<ul><li ng-repeat="(key, person) in people |orderBy 'name'"></li></ul>

我得到:


  • -JZ7a康妮有松弛

  • -JZ7b鲍勃松弛

这里有一个小提琴

什么是获得预期ORDERBY <一个最好的方式href=\"http://stackoverflow.com/questions/14330878/angular-js-orderby-not-working-with-dict-syntax-on-ng-repeat\">without改变我的数据转换成其他格式?我意识到,在本实施例中的键是不完全有意义,但假定它们。一个建立一个自定义指令的想法似乎是一个有趣的选择,但是,我的code可以是一个有点jangly比较原始。

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.

推荐答案

排序依据不适用的对象。您可以使用过滤器的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>

演示: http://jsfiddle.net/62exD/

这篇关于我怎么angularFire对象排序依据与ngRepeat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆