I am currently seeking a way to retrieve deeply nested JSON data from a firebase database in order to utilize it within a listView
. This approach has been successfully implemented throughout my application, but I am facing challenges when attempting to access dynamic properties of the children data.
An example export of the JSON data from my database is as follows:
{
"T&G Canary Wharf" : {
"Administrator" : {
"1550633367665" : {
"date" : "2019-02-12T12:00:00.000",
"details" : "Full Day",
"name" : "Edward Lawrence",
"status" : "pending"
},
"1550633370715" : {
"date" : "2019-02-13T12:00:00.000",
"details" : "Full Day",
"name" : "Edward Lawrence",
"status" : false
},
"1550845072137" : {
"date" : "2019-02-12T12:00:00.000",
"details" : "Full Day",
"name" : "Katie Prescott ",
"status" : 1
},
},
"Stylist": {
"1551222170677": {
"date": "2019-02-19T12:00:00.000",
"details": "Full Day",
"name": "Stylist Stylist",
"status": "pending"
}
}
}
}
In the context of the app user, the group
(e.g., T&G Canary Wharf) will always be specified, while the subgroup
(such as Administrator & Stylists) varies dynamically for administrators, presenting an obstacle that I am currently grappling with.
Below you can find the code snippet used for reading data from the Firebase database:
The framework employed here is felgo(formerly v-play), and attached is a link to their Firebase documentation:
Felgo Firebase Plugin
App {
property var adminModel: []
property var groupName //the group name is assigned onLoggedIn, in this example group name === T&G Canary Wharf
FirebaseDatabase {
onLoggedIn: {
firebaseDb.getValue("groups" + "/" + groupName, {
orderByValue: true
}, function(success, key, value) {
if(success){
console.log("ADMIN MODEL: " + JSON.stringify(value))
adminModel = value // my array where I intend to push the data too
}
})
}
}
}
Further enlightening discussions about accessing or processing nested objects, arrays, or JSON data can be found on:
access/process nested objects, arrays or JSON
(remarkably informative by the way!), especially focusing on the part labeled "What if the property names are dynamic and I don't know them beforehand?"
The challenge I face lies in creating two list entries for Administrator
and Stylist
subGroups where the child key is also dynamic (reflecting the time the entry was created, e.g., "1550633367665"). Unfortunately, I encounter difficulties progressing beyond this point.
To elaborate further on how this modelis created, below is the related code section:
ListPage {
id: adminPage
model: Object.keys(adminModel)
delegate: SwipeOptionsContainer {
id: container
rightOption: SwipeButton {
anchors.fill: parent
backgroundColor: "red"
icon: IconType.trash
onClicked: {
container.hideOptions()
}
}
SimpleRow {
id: userRow
width: parent.width
text: modelData
}
}
}
Presenting My Question:
How can I construct a listView
with delegates representing any object containing a "status" : "pending"
? While similar implementation has been carried out using a loop such as
if (value[i].status === pending) { arr.push({...})}
, the challenge arises when dealing with an unknown subgroup (Stylist/Administrator)
. In other words, although the database example comprises only two list elements, there could potentially be numerous more with varied subGroup
scenarios.