【发布时间】:2018-11-18 11:27:15
【问题描述】:
我使用 Firebase 实时数据库。 我在数据库中有以下排行榜数据:
Leaders:
0
Name: Michal
Score: 40
1
Name: David
Score: 35
2
Name: Rob
Score: 53
除了OrderByChild 不会排序之外,我正在读取运行良好的数据。
我认为这与我使用数组编号保存有关。
注意:我不使用任何奇怪的方法来使用数组保存数据,但实际上是使用 Unity 事务的谷歌示例,话虽如此,我希望 OrderByChild 能够工作。 Transactions, see bottom of screen
这是检索数据的代码:
FirebaseDatabase.DefaultInstance
.GetReference("Leaders").OrderByChild("score").GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted)
{
Debug.LogError("error in reading LeaderBoard from DB");
return;
}
else if (task.IsCompleted)
{
Debug.Log("Received values for Leaders.");
string JsonLeaderBaord = task.Result.GetRawJsonValue();
callback(JsonLeaderBaord);
}
}
我确实尝试添加 onIndex 规则,但还是一样,它忽略了排序。
【问题讨论】:
-
您可以发送您真实的 Firebase 数据的屏幕截图吗?也许有隐藏的名字?
-
@laltin 在firebase中添加了真实数据的照片
-
这可能是您的键是数组索引的问题。 Firebase 不建议存储数组。所以我的建议是将键从数字(0、1、..)更改为一些字符串
标签: c# firebase unity3d firebase-realtime-database