基本上,我试图查询对某则帖子所做的评论。因此,Im首先在数据库中查询Posts(键)及其所有相应数据。.依次包括ReviewID的这些ID列表,您可以在数据库图片中看到这些ID。所有这些我都获得了成功,问题是当我需要从firebase中获取评论数据时,它告诉我快照为null...。我已经阅读了几件事,并且我相信这可能与能够在查询中进行查询..任何人都可以帮助阐明这一点。我不确定该怎么做,因为获取相应的评论依赖于AddPost节点中的数据(这样做是为了避免数据被嵌套!)
//在此处获取帖子
func getPost(withKey key: String, completion: @escaping (_ addPost: AddPost?) -
> ()) {
REF_ADDS.child(key).observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshot = snapshot.value as? Dictionary<String,AnyObject> {
let addPost = AddPost(postKeyId: key, postData: snapshot)
let reviewKeys = addPost.reviewIDs
print("\(reviewKeys)")
// Having Issues Here. am successfully getting the keys above^
for key in reviewKeys {
self.getReview(withKey: key, completion: { (reviews) in
})
}
completion(addPost)
}
})
}
//在这里获得相应的评论
func getReview(withKey key: String, completion: @escaping (_ reviews: ReviewPost?) -> ()) {
REF_REVIEWPOST.child(key).observeSingleEvent(of: .value) { (snapshot) in
print("getreviewsnapshot\(snapshot.value)")
if let snapshot = snapshot.value as? Dictionary<String,AnyObject> {
let review = ReviewPost(key: key, postData: snapshot)
completion(review)
}
}
}
// Firebase JSON
{
"AddPost" : {
"-LIGEc5BRdMDPCOLaGIE" : {
"endTime" : "02:41 PM 25/07/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F404483C2-1540-4E7B-86BC-5714CE2567E8?alt=media&token=421f4182-d364-41de-ba46-ebc8c6bcf78c",
"live" : true,
"locationName" : "",
"postTitle" : "first test post",
"reviews" : {
"testttt" : true
},
"startTime" : "01:41 PM 25/07/2018",
"views" : 0
},
"-LIHJ3343uFw3vgkimk3" : {
"endTime" : "07:41 PM 25/07/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F7BCC4D95-2F6D-405A-B9A2-4FBCB573514E?alt=media&token=94d76335-faf3-4437-b64d-0412cbdbd15f",
"live" : true,
"locationName" : "",
"postTitle" : "anotherTestAdd",
"startTime" : "06:40 PM 25/07/2018",
"views" : 0
},
"-LIQ_Aa8s1H067wFeCdR" : {
"endTime" : "20:51PM 17/07/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F9310AD91-3744-4BC7-BB9F-29E423BC6675?alt=media&token=2e2efd5c-6d50-443e-9e8e-6901663a3c8b",
"live" : true,
"locationName" : "",
"postTitle" : "Dumplings For FREE",
"reviews" : {
"-LKytNJZcNwrNom9mfhx)" : true
},
"startTime" : "19:51PM 27/07/2018",
"views" : 0
},
"-LIQjFPOYrNkRTCquRrP" : {
"endTime" : "22:35PM 27/07/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F59472C4A-C8C5-4B9F-B72F-FAC00DE3624D?alt=media&token=bb81a21f-f367-4eac-b562-22b417e8f3ed",
"live" : true,
"locationName" : "",
"postTitle" : "Chicken Noodles 9.99",
"reviews" : {
"-LKysthgvVyfjVf3nlNR)" : true,
"-LL-6TMwUvyohrDXHmMU" : true
},
"startTime" : "20:35PM 27/07/2018",
"views" : 0
},
"-LIR6OEX48lAnInecbx3" : {
"endTime" : "05:21 PM 27/07/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F782B0D7A-85E9-4ADA-A824-B5B094ABF4BA?alt=media&token=4cb5ffa5-b2a7-447f-b4aa-16ffccaa0e6d",
"live" : true,
"locationName" : "",
"postTitle" : "testpost",
"startTime" : "04:21 PM 27/07/2018",
"views" : 0
},
"-LIR8wRCXBirrYI4TrkA" : {
"endTime" : "05:32 PM 27/07/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FA2543B6C-ECD2-4106-A8B0-FB9F73089EF1?alt=media&token=2d04f2c4-2048-4719-bd93-e58faf6837e8",
"live" : true,
"locationName" : "",
"postTitle" : "hahahahaha ",
"reviews" : {
"-LIfeMknU_5uZQ0rKr20)" : true,
"-LIfeQMzo8gMNqHAd7O2)" : true
},
"startTime" : "04:32 PM 27/07/2018",
"views" : 0
},
"-LJ3EjqT2xu1BCowKg-w" : {
"endTime" : "11:20 AM 04/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FEBFB8D3F-31B6-4D13-856C-EE054B8AFC53?alt=media&token=74ec2aac-d3af-4ecf-99c2-87d92e8125bc",
"live" : true,
"locationName" : "La desgracia ",
"postTitle" : "two for one beers ",
"startTime" : "10:20 AM 04/08/2018",
"views" : 0
},
"-LL-5s5j_JnfDJn2UyVM" : {
"endTime" : "12:36 PM 29/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F7ABE207E-BBA4-467E-8956-C9AFF1D17FCF?alt=media&token=c40e0a05-ad28-49f5-ac5e-cbad4adf0cfb",
"live" : true,
"locationName" : "la previa",
"postTitle" : "la previa",
"startTime" : "12:36 PM 28/08/2018",
"views" : 0
},
"-LL-7Y1mw7DvQPb-uC8Z" : {
"endTime" : "19:43PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F548E96B8-A055-4615-8399-EB17D33D4184?alt=media&token=408992af-99e8-4e48-95fc-5bc8fe327097",
"live" : true,
"locationName" : "",
"postTitle" : "a name",
"startTime" : "18:43PM 28/08/2018",
"views" : 0
},
"-LL-9cU88j4mZkonAFw2" : {
"endTime" : "20:52PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F9AAB98CF-AA20-43BE-AFB7-63811E15B685?alt=media&token=74ed6447-b6b7-42cd-9db6-31a7b41f1c60",
"live" : true,
"locationName" : "",
"postTitle" : "Some stuff",
"startTime" : "18:52PM 28/08/2018",
"views" : 0
},
"-LL-CPtZhtpHtT0PwvOH" : {
"endTime" : "01:05 PM 18/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FC6075A46-2ADE-495A-87C5-1180B47A9933?alt=media&token=9bc6fd5a-f7ca-4710-9691-a8e50fce250e",
"live" : true,
"locationName" : "la previa",
"postTitle" : "hombre",
"startTime" : "01:04 PM 18/08/2018",
"views" : 0
},
"-LL-G10SOxOlC-Mq2K0k" : {
"endTime" : "01:20 PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F784E67BE-3D2C-44C6-A0F8-C1FBAFE5C5D5?alt=media&token=aea5b7fe-bd9d-4b90-8c6d-d568fe3ad3c2",
"live" : true,
"locationName" : "la previa",
"postTitle" : "ahha",
"startTime" : "01:20 PM 18/08/2018",
"views" : 0
},
"-LL-Gd6NkAVCl5EjV_wy" : {
"endTime" : "21:23PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FD305CE5C-6865-4C14-A7CF-2E5DD8291116?alt=media&token=6fc0ffc8-4f61-4198-818b-e41857fa0190",
"live" : true,
"locationName" : "",
"postTitle" : "Beef Super Noodles",
"reviews" : {
"-LL-Gz7N4qx_t0vYnsnn" : true
},
"startTime" : "20:23PM 28/08/2018",
"views" : 0
},
"-LL-HWJ_pan1DC1RVC11" : {
"endTime" : "23:26PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FAD49348A-AB8F-4362-9E02-ABAE45BB8A71?alt=media&token=06be5ba5-c555-4d26-a06b-dd752ec7b8b1",
"live" : true,
"locationName" : "",
"postTitle" : "Fast Dumplings Forever",
"startTime" : "18:26PM 28/08/2018",
"views" : 0
},
"-LL-JBuCmVANW_wRlc6Y" : {
"endTime" : "20:34PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F24FA64CB-7E58-45A3-94EE-1E7FC0922232?alt=media&token=1d537867-8d91-4ea5-bac8-e2e402dbec99",
"live" : true,
"locationName" : "",
"postTitle" : "Fish tart",
"startTime" : "19:34PM 28/08/2018",
"views" : 0
},
"-LL-MKQhf2XGp3uEfWxw" : {
"endTime" : "01:48 PM 18/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FE2EF7170-00C0-4B4D-B299-631647080009?alt=media&token=87b54b2c-0720-4d02-9a8f-14c73e8936cb",
"live" : true,
"locationName" : "la previa",
"postTitle" : "as?",
"startTime" : "01:48 PM 18/08/2018",
"views" : 0
},
"-LL-Mi43AcCE1CjA_Z1z" : {
"endTime" : "20:50PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FA32A8B49-99FB-4353-8DF5-A9F9AC1AF506?alt=media&token=afd11f86-a02c-4680-a26b-54c8d43305f9",
"live" : true,
"locationName" : "",
"postTitle" : "Kawabanga",
"startTime" : "19:50PM 28/08/2018",
"views" : 0
},
"-LL-NJ2EvSKhYjgQ5j5M" : {
"endTime" : "20:52PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F0113B93A-36ED-4A37-B02D-2098C1FF3600?alt=media&token=d9c83883-9f41-495c-a7e7-4aaa33d6eaf6",
"live" : true,
"locationName" : "",
"postTitle" : "some sad stuff",
"startTime" : "20:52PM 28/08/2018",
"views" : 0
},
"-LL-P6dK9SaQ2wvhvjXl" : {
"endTime" : "21:00PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FA57F2466-9E6F-45E4-85CD-2AFBAE0D1CF5?alt=media&token=93be27a0-b70b-436f-8e5e-16d5f3d051b4",
"live" : true,
"locationName" : "",
"postTitle" : "fakdkfm",
"startTime" : "20:00PM 28/08/2018",
"views" : 0
},
"-LL-PE13Mbc-aB-uzlTo" : {
"endTime" : "02:01 PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FF628CBE2-B34C-48F2-AD9F-AF7F889716C7?alt=media&token=674d107b-706b-426e-9205-f6497c37f311",
"live" : true,
"locationName" : "la previa",
"postTitle" : "test",
"startTime" : "02:00 PM 28/08/2018",
"views" : 0
},
"-LL-S3BSycT6jCGYrQKb" : {
"endTime" : "02:13 PM 18/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2F46E21030-F88B-463A-8A76-64B92C02B42B?alt=media&token=e013e775-3fab-41dc-88b7-0577cf1c48ea",
"live" : true,
"locationName" : "la previa",
"postTitle" : "ah",
"startTime" : "02:13 PM 28/08/2018",
"views" : 0
},
"-LL-SMMxpgT2w-aC0HK5" : {
"endTime" : "20:15PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FB0D6A779-ECA0-4856-873F-CF8B72058AC0?alt=media&token=6d25e66a-4fd3-43ab-b7c8-df3a0d37de9d",
"live" : true,
"locationName" : "",
"postTitle" : "ggggg",
"startTime" : "20:14PM 28/08/2018",
"views" : 0
},
"-LL-Sur61fCG8Uz9_NRU" : {
"endTime" : "20:17PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FC0D9C742-3432-47F4-B54B-E87C923D32EB?alt=media&token=f187e783-d251-48f4-ac3a-c5ae808ff092",
"live" : true,
"locationName" : "",
"postTitle" : "Noname",
"startTime" : "20:17PM 28/08/2018",
"views" : 0
},
"-LL-UiIvutVi0BqCJM-S" : {
"endTime" : "02:25 PM 28/08/2018",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/posts%2FAA9D0DF5-455D-4BC1-9496-DFB3CED331EE?alt=media&token=de25c0ed-50d6-448d-8e30-54891837d08a",
"live" : true,
"locationName" : "la previa",
"postTitle" : "hahahahaha ",
"startTime" : "02:25 PM 18/08/2018",
"views" : 0
}
},
"Geolocs" : {
"6oQkKd6KWFfBHZKpe6qAU3nGdzE2" : {
"g" : "ezjpm00vzk",
"l" : [ 40.6504274, -3.997676599999999 ]
},
"IMDdQqucvubaoCQK37ih1WW0SCE2" : {
"g" : "ezjphu9ryz",
"l" : [ 40.6315578, -4.0079973 ]
},
"LUtRmkAefPNsRjPni5Dn0KAvKBx1" : {
"g" : "w7jzu4b4s3",
"l" : [ 18.252847, 109.511909 ]
},
"iY92WUP59NfBwpPooRvcCMtOt5A2" : {
"g" : "w7jzspq2y7",
"l" : [ 18.23333, 109.520572 ]
},
"m0dOavnabOOwvU2D96gOAZMHN8H2" : {
"g" : "ezjpkbw83c",
"l" : [ 40.6522097, -4.0010055 ]
},
"shAsayRaoWSreayG5wKF2aTPMkh1" : {
"g" : "ezjpm003w9",
"l" : [ 40.64967947910633, -3.9984001591801643 ]
},
"vKdlBRpiiTS3IArFhTo8KHCRN0H2" : {
"g" : "ezjpkbpr3n",
"l" : [ 40.65069163457745, -4.0000031143426895 ]
},
"x748UBl3VRQk5zdruYKjw5RayTt1" : {
"g" : "9q8yyrpvjx",
"l" : [ 37.78837619999999, -122.4097711 ]
}
},
"ReviewPost" : {
"-LINUam-sdDpLpPYPlnL" : {
"addPostID" : "-LIGEc5BRdMDPCOLaGIE",
"rating" : 5,
"reviewComment" : "This is test review ",
"time" : "2018-07-26 21:28:41 +0000",
"userID" : "IMDdQqucvubaoCQK37ih1WW0SCE2"
},
"-LIfd7XGrHXpftKvZN3I" : {
"addPostID" : "-LIR8wRCXBirrYI4TrkA",
"rating" : 5,
"reviewComment" : "Test comment /review :) ",
"time" : "2018-07-30 14:43:06 +0000",
"userID" : "shAsayRaoWSreayG5wKF2aTPMkh1"
},
"-LIfdIGpdo2ZTk03sh7F" : {
"addPostID" : "-LIGEc5BRdMDPCOLaGIE",
"rating" : 5,
"reviewComment" : "Another test ",
"time" : "2018-07-30 14:43:50 +0000",
"userID" : "shAsayRaoWSreayG5wKF2aTPMkh1"
},
"-LIfdTGE5adLuyIwhNtf" : {
"addPostID" : "-LIGEc5BRdMDPCOLaGIE",
"rating" : 5,
"reviewComment" : "Test2",
"time" : "2018-07-30 14:44:35 +0000",
"userID" : "shAsayRaoWSreayG5wKF2aTPMkh1"
},
"-LIfeMknU_5uZQ0rKr20" : {
"addPostID" : "-LIR8wRCXBirrYI4TrkA",
"rating" : 5,
"reviewComment" : "Test 3",
"time" : "2018-07-30 14:48:30 +0000",
"userID" : "shAsayRaoWSreayG5wKF2aTPMkh1"
},
"-LIfeQMzo8gMNqHAd7O2" : {
"addPostID" : "-LIR8wRCXBirrYI4TrkA",
"rating" : 5,
"reviewComment" : "Otra test en la ",
"time" : "2018-07-30 14:48:45 +0000",
"userID" : "shAsayRaoWSreayG5wKF2aTPMkh1"
},
"-LKysthgvVyfjVf3nlNR" : {
"addPostID" : "-LIQjFPOYrNkRTCquRrP",
"rating" : 5,
"reviewComment" : "Shitty place",
"time" : "2018-08-28 04:56:10 +0000",
"userID" : "LUtRmkAefPNsRjPni5Dn0KAvKBx1"
},
"-LKytNJZcNwrNom9mfhx" : {
"addPostID" : "-LIQ_Aa8s1H067wFeCdR",
"rating" : 5,
"reviewComment" : "Dumplings were rubbish.",
"time" : "2018-08-28 04:58:18 +0000",
"userID" : "LUtRmkAefPNsRjPni5Dn0KAvKBx1"
},
"-LL-6TMwUvyohrDXHmMU" : {
"addPostID" : "-LIQjFPOYrNkRTCquRrP",
"rating" : 5,
"reviewComment" : "Rubishhhhhhh",
"time" : "2018-08-28 10:39:27 +0000",
"userID" : "LUtRmkAefPNsRjPni5Dn0KAvKBx1"
},
"-LL-Gz7N4qx_t0vYnsnn" : {
"addPostID" : "-LL-Gd6NkAVCl5EjV_wy",
"rating" : 5,
"reviewComment" : "That was awesome!!!!!!",
"time" : "2018-08-28 11:25:23 +0000",
"userID" : "iY92WUP59NfBwpPooRvcCMtOt5A2"
}
},
"Users" : {
"208icyabSsT5jYhbxhPgIv4JmjF2" : {
"City" : "Abhudabi ",
"Country" : "Mars",
"Name" : {
"Nickname" : "Vvvvvvvv"
},
"isBusiness" : false
},
"6oQkKd6KWFfBHZKpe6qAU3nGdzE2" : {
"businessName" : "Tarssss",
"city" : "Collado Villalba ",
"country" : "Spain",
"isBusiness" : true,
"lat" : 40.6504274,
"lon" : -3.997676599999999,
"ownersName" : "Tar",
"postcode" : "28400",
"state" : "Madrid",
"street" : "Calle la chopera 3"
},
"7qk6HTr6jxV23GeF1C6faOrXSkm2" : {
"businessName" : "Ya",
"city" : "Collado Villalba ",
"country" : "Spain",
"isBusiness" : true,
"ownersName" : "Ya",
"postcode" : "28400",
"state" : "Madrid",
"street" : "Calle la chopera 2 "
},
"9XUMX4iTeogAj4KS3Icu77jDCbC2" : {
"businessName" : "T",
"city" : "Collado Villalba ",
"country" : "Spain",
"isBusiness" : true,
"ownersName" : "T",
"postcode" : "28400",
"state" : "Madrid",
"street" : "Calle la chopera 2 "
},
"AmUqAzjf3gXvLGPzV8O7KE3Q5tq2" : {
"City" : "Fndksks",
"Country" : "Dnmddkk",
"Name" : {
"Nickname" : "Alfjfkk"
},
"isBusiness" : false
},
"BihBfwdWKhazFwuLtWFTo31GAu42" : {
"City" : "VC",
"Country" : "Vvvvv",
"Name" : {
"Nickname" : "VC"
},
"isBusiness" : false
},
"FysXUqOJ1aXyQGYyhg03AtO09my2" : {
"city" : "Amfkdkdkdkd",
"country" : "Xmxkkxkdkdkd",
"isBusiness" : false,
"name" : "Aldo"
},
"IMDdQqucvubaoCQK37ih1WW0SCE2" : {
"addPosts" : {
"-LIHJ3343uFw3vgkimk3" : true,
"-LL-5s5j_JnfDJn2UyVM" : true,
"-LL-CPtZhtpHtT0PwvOH" : true,
"-LL-G10SOxOlC-Mq2K0k" : true,
"-LL-MKQhf2XGp3uEfWxw" : true,
"-LL-PE13Mbc-aB-uzlTo" : true,
"-LL-S3BSycT6jCGYrQKb" : true,
"-LL-UiIvutVi0BqCJM-S" : true
},
"businessName" : "la previa",
"email" : "laprevia@hotmail.com",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/ProfilePics%2FD7617CAA-B31A-468C-8D8A-FCAA6265CC3A?alt=media&token=06a313bf-2db1-414c-a0d0-483b23872063",
"isBusiness" : true,
"lat" : 40.6315578,
"lon" : -4.0079973,
"profileName" : "tar",
"reviews" : {
"-LINUam-sdDpLpPYPlnL" : true
}
},
"LUtRmkAefPNsRjPni5Dn0KAvKBx1" : {
"addPosts" : {
"-LIQ_Aa8s1H067wFeCdR" : true,
"-LIQjFPOYrNkRTCquRrP" : true,
"-LL-7Y1mw7DvQPb-uC8Z" : true,
"-LL-9cU88j4mZkonAFw2" : true
},
"businessName" : "DumplingMania",
"city" : "Sanya",
"country" : "China",
"imageUrl" : "https://firebasestorage.googleapis.com/v0/b/foodies-a4b80.appspot.com/o/ProfilePics%2F38E4C97A-B636-452A-92FD-3A179BFB15A9?alt=media&token=687b0096-758d-4055-864a-19db67722313",
"isBusiness" : true,
"lat" : 18.252847,
"lon" : 109.511909,
"ownersName" : "Mr. Dumpling",
"postcode" : "572000",
"reviews" : {
"-LKysthgvVyfjVf3nlNR" : true,
"-LKytNJZcNwrNom9mfhx" : true,
"-LL-6TMwUvyohrDXHmMU" : true
},
"state" : "Hainan",
"street" : "Hedong"
},
"ZhnyfjmjG4P3kQKxWI74y55OeVj2" : {
"City" : "Mick city ",
"Country" : "Mars",
"Name" : {
"Nickname" : "Nick nickname"
},
"isBusiness" : false
},
"iY92WUP59NfBwpPooRvcCMtOt5A2" : {
"addPosts" : {
"-LL-Gd6NkAVCl5EjV_wy" : true,
"-LL-HWJ_pan1DC1RVC11" : true,
"-LL-JBuCmVANW_wRlc6Y" : true,
"-LL-Mi43AcCE1CjA_Z1z" : true,
"-LL-NJ2EvSKhYjgQ5j5M" : true,
"-LL-P6dK9SaQ2wvhvjXl" : true,
"-LL-SMMxpgT2w-aC0HK5" : true,
"-LL-Sur61fCG8Uz9_NRU" : true
},
"businessName" : "NoodleDoodle",
"city" : "Sanya",
"country" : "China",
"isBusiness" : true,
"lat" : 18.23333,
"lon" : 109.520572,
"ownersName" : "NoodleDoodle",
"postcode" : "572000",
"reviews" : {
"-LL-Gz7N4qx_t0vYnsnn" : true
},
"state" : "Hainan",
"street" : "Fenghuang"
},
"m0dOavnabOOwvU2D96gOAZMHN8H2" : {
"addPosts" : {
"-LIGEc5BRdMDPCOLaGIE" : true
},
"businessName" : "testBusiness1",
"email" : "test1@hotmail.com",
"imageUrl" : "defaultImgHere?",
"isBusiness" : true,
"lat" : 40.6522097,
"lon" : -4.0010055,
"profileName" : "test1"
},
"shAsayRaoWSreayG5wKF2aTPMkh1" : {
"businessName" : "Gemany",
"city" : "Collado Villalba",
"country" : "Spain",
"isBusiness" : true,
"lat" : 40.64967947910633,
"lon" : -3.9984001591801643,
"ownersName" : "Gema ",
"postcode" : "28400",
"reviews" : {
"-LIfd7XGrHXpftKvZN3I" : true,
"-LIfdIGpdo2ZTk03sh7F" : true,
"-LIfdTGE5adLuyIwhNtf" : true,
"-LIfeMknU_5uZQ0rKr20" : true,
"-LIfeQMzo8gMNqHAd7O2" : true
},
"state" : "Madrid",
"street" : "Calle la chopera "
},
"uU6IAhEUKzQXTK4P4Gn4zn0gIjB3" : {
"City" : "Fmcmdk",
"Country" : "Ndsmmskx",
"Name" : {
"Nickname" : "Flank"
},
"isBusiness" : false
},
"vKdlBRpiiTS3IArFhTo8KHCRN0H2" : {
"addPosts" : {
"-LIR8wRCXBirrYI4TrkA" : true
},
"businessName" : "Hola ",
"city" : "Collado Villalba ",
"country" : "Spain ",
"isBusiness" : true,
"lat" : 40.6500548,
"lon" : -3.9976061,
"ownersName" : "Hola ",
"postcode" : "28400",
"state" : "Madrid ",
"street" : "Calle chopera 2"
},
"x748UBl3VRQk5zdruYKjw5RayTt1" : {
"Business Name" : "Dumplings Inc.",
"City" : "Dumpling City",
"Country" : "Dumpling Country",
"Owners Name" : {
"Nickname" : "Dumpling Master"
},
"Postcode" : "0112233",
"State" : "Dumpling State",
"Street" : "Big Street",
"lat" : 37.78837619999999,
"lon" : -122.4097711
},
"yMIiHPtJQdYspZhK61ZQa0MqNan1" : {
"City" : "V",
"Country" : "V",
"Name" : {
"Nickname" : "Val"
},
"isBusiness" : false
}
}
}
答案 0 :(得分:0)
代码可能还有其他问题,但我建议使用其他方法。与其紧密地阅读每个帖子的评论,不如在每个评论中包含post_id,然后通过简单的查询将其读入。
flex: 1 1 16.5%;
max-width: 16.5%;
然后获取有关post_id_0的所有评论
Posts
"post_id_0" : { //childByAutoId()
"endTime" : "05:32 PM 27/07/2018",
"imageUrl" : "",
"live" : true,
"locationName" : "",
"postTitle" : "hahahahaha ",
"reviews" : {
"review_id_0" : true,
"review_id_1" : true
},
"startTime" : "04:32 PM 27/07/2018",
"views" : 0
ReviewPost
"review_id_0" : { //childByAutoId()
"post_id": "post_id_0", //a reference to the post
"addPostID" : "-LIQ_Aa8s1H067wFeCdR",
"rating" : 5,
"reviewComment" : "Dumplings were rubbish.",
"time" : "2018-08-28 04:58:18 +0000",
"userID" : "LUtRmkAefPNsRjPni5Dn0KAvKBx1"
},
,输出为
let reviewPostRef = self.ref.child("ReviewPost")
let query = reviewPostRef.queryOrdered(byChild: "post_id").queryEqual(toValue: "post_id_0")
query.observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let childSnap = child as! DataSnapshot
let dict = childSnap.value as! [String: Any]
let comment = dict["reviewComment"] as! String
print(comment)
}
})