gpt4 book ai didi

ios - Firebase 数据过滤

转载 作者:行者123 更新时间:2023-11-30 13:02:58 24 4
gpt4 key购买 nike

我有以下 Firebase JSON 数据结构;

  {
"USERS": {
"YjGJsvCb58OsTThv6JLmK1dMuHr1": {
"Email": "test@test.com"
},
"zQpb7o18VzYsSoTQtT9DNhOqTUn2": {
"Email": "test2@test.com"
}
},
"POSTS": {
"-KSe4eJyenccPoC5T0zP": {
"addedByUser": "YjGJsvCb58OsTThv6JLmK1dMuHr1",
"content": "Post 1",
"cost": "600",
"duration": "Quarterly",
"latitude": "51.5099850000001",
"longitude": "-0.133528614416432",
"timestamp": "Tue 27 Sep"
},
"-KSe4q1DXoulArzWm_Zm": {
"addedByUser": "YjGJsvCb58OsTThv6JLmK1dMuHr1",
"content": "Post 2",
"cost": "550",
"duration": "Monthly",
"latitude": "51.5100199999855",
"longitude": "-0.133507191218496",
"timestamp": "Tue 27 Sep"
}
}
}

我想过滤POSTS并获取所有持续时间每月或以用户为准的POSTS已选择。正如您所看到的,每个 POST 都分配有一个 AutoID

我正在寻找的结果应该会输出:

  {
"-KSe4q1DXoulArzWm_Zm": {
"addedByUser": "YjGJsvCb58OsTThv6JLmK1dMuHr1",
"content": "Post 2",
"cost": "550",
"duration": "Monthly",
"latitude": "51.5100199999855",
"longitude": "-0.133507191218496",
"timestamp": "Tue 27 Sep"
}
}

但我一生都无法搜索 AutoID。我已经尝试了几乎所有的 queryForobserve 方法。我已经搜索过 StackOverflow,但似乎没有解决方案有效。我的数据结构是否正确?我需要 AutoID 的原因是某些帖子可能是相同的。

任何帮助将不胜感激。

最佳答案

试试这个:-

FIRDatabase.database().reference().queryOrdered(byChild: "POSTS").queryEqual(toValue: "monthly").observeSingleEvent(of: .value, with: {(snap) in


if let postsDict = snap.value as! [String:AnyObject]{

for each in postsDict {

print(each)

}

}else{

//That username doesnt exists.

}

})

关于ios - Firebase 数据过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39716830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com