Hello!
I have been cleaning up my code, whilst trying to implement the ability for users to delete database entries in my Firebase Realtime Database, I have been following the example in: https://felgo.com/cross-platform-app-development/firebase-qml-tutorial-android-ios-create-an-app-with-realtime-database-and-login as it matches well with my use-case.
Within my database, dates are stored with and ‘id’ of the time they were saved, and also nested further is batch saved dates from multi select(an absolute must for my app)
I am having 2 issues,
- even when using exactly as detailed in the above link, I am unable to delete database entries (they are stored by the time they are created as in example)
- creating my listView from nested-nested JSON data.
An extract of my JSON is:
{
"1551925260120" : {
"date" : "2019-03-11T12:00:00.000",
"name" : "Edward Lawrence"
},
"1551925261236" : {
"date" : "2019-03-12T12:00:00.000",
"name" : "Edward Lawrence"
},
"1551925268753" : [ {
"date" : "2019-03-20T12:00:00.000",
"name" : "Edward Lawrence"
}, {
"date" : "2019-03-21T12:00:00.000",
"name" : "Edward Lawrence"
}, {
"date" : "2019-03-22T12:00:00.000",
"name" : "Edward Lawrence"
} ]
}
and the code for my ListPage and firebase read is:
import Felgo 3.0
import QtQuick 2.5
ListPage {
id: userPage
title: "User Page"
property var calendarItems: ({})
readonly property string dbKeyAllCalendarItems: "groups" + "/" + groupName + "/" + subGroupName
model: Object.keys(calendarItems)
readonly property var calendarItem: calendarItems[modelData] || {}
SimpleRow {
id: userRow
width: parent.width
text: container.calendarItem.name
detailText: new Date(container.calendarItem.date).toLocaleDateString(Qt.locale(),"dddd "+ "MMM "+ "dd "+ "yyyy") || ""
}
}
FirebaseDatabase {
id: firebaseDb
config: customConfig
firebaseDb.getValue(dbKeyAllCalendarItems, {
orderByValue: true
}, function(success, key, value) {
if(success){
var addedItems = value
var readcalendarItems = value
var subGroups = Object.keys(readcalendarItems);
for(var inx in subGroups) {
var sg = readcalendarItems[subGroups[inx]];
var timeEntries = Object.keys(sg);
var filteredEntries = timeEntries.filter(function(t) { return sg[t].name === userName + " " + userSurname; });
var filteredEntries2 = filteredEntries.map(function(t) { return sg[t]; });
calendarItems = filteredEntries2 && addedItems
}
}
FirebaseConfig {
id: customConfig
projectId: "MYID"
databaseUrl: "MYURL"
apiKey: Qt.platform.os === "android"
? "NUMBERSANDLETTERS"
: "MORENUMBERSANDLETTERS"
applicationId: Qt.platform.os === "android"
? "IBETYOUKNOWWHATIMGOINGTOSAY"
: "YOURERIGHTNONUMBERSANDLETTERS"
}
}
the closest I have gotten to a solution is the above code. the result of this are both days are created as list entries, but the further nested one is a blank list entry.
If I remove the && addedItems and keep calendarItems as just the result of filteredEntries2, I get only 3 list entries of the nested dates(not the higher 2).
alternatively if I drop the function/loop, and just set my firebase value to calendarItems = value || {} as in the demo I only retrieve the two non nested entries for my list!
Help!
Edd