6

I'm looking into implementing an in-firebase index as described here: https://stackoverflow.com/a/10559689/534086, and trying to figure out how to deal with sorting data in descending order. Is it possible if you have a node with children 'a', 'b', 'c' to retrieve them 'c', 'b', 'a'? (while still being able to retrieve them in the original order as well?)

If it's not possible to traverse the node both forwards and backwards and I need to create two indexes, is their an easy algorithm for generating keys that sort in reverse lexographic order? For numbers, I think you can multiply by -1, but not sure how to handle strings...

4

2 に答える 2

9

「limit()」が現在どのように機能するかに似た「reverse()」クエリが必要なようです。Firebase ではまだこれを実行できませんが、追加する予定です。

ユースケースによっては、これを回避するのは非常に簡単かもしれません。たとえば、Firebase の並べ替えを使用して、ユーザーに表示される順序でリストを保持している場合、表示ロジックを単純に変更して、物事を逆方向にレンダリングすることができます (たとえば、追加ではなくアイテムを前に追加します)。大量の子セットからデータのウィンドウを選択するクエリを実行している場合 (たとえば、長いリストから最初の 10 項目を取得する場合)、並べ替え順序は重要ではありません。クエリは、逆になることを除いて同じままです。

于 2013-02-28T04:58:13.553 に答える
0

結果セットを自分で使用limitToLast()およびソートできますか? たまたまAngularを使用している場合、この種のことが機能することを私は知っています。ここitemsで、$scopeのFirebase配列オブジェクトです。

<li ng-repeat="item in items | orderBy:'-fieldName'"> {{ item.fildName }}</li>
于 2015-06-03T12:15:17.843 に答える