FireBase iOS queryOrderedByChild无效

时间:2014-11-11 14:20:23

标签: ios firebase

我从下面的代码中获得结果,但它们不符合指定的顺序。

Firebase *myRootRef = [[Firebase alloc] initWithUrl:@"https://xxxxxxxxx.firebaseio.com"];
Firebase *updates = [[myRootRef childByAppendingPath:@"data"] childByAppendingPath:@"Offences"];
[updates queryOrderedByChild:@"dateUpdated"];
[updates observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
    NSLog(@"VALUE: %@", snapshot.value);
 }];

孩子Offences是这样的JSON数组......

[ {
  "dateUpdated" : 20140915,
  "name" : "Bla bla bla"
}, {
  "dateUpdated" : 20140912,
  "name" : "Bla bla bla"
}, {
  "dateUpdated" : 20140914,
  "name" : "Bla bla bla"
} ]

我怀疑它是在数组中导致问题的事实,任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:3)

调用queryOrderedByChild 返回修改后的查询。所以你需要链接mehthod调用:

[[updates queryOrderedByChild:@"dateUpdated"] observeEventType:FEventTypeChildAdded...]

参见示例"使用子键排序"在这里:https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-ordered-data