Forums

OverviewFelgo 2 Support (Qt 5) › Object.keys() with nested JSON Data

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #21236

    Edward

    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,

    1. 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)
    2. 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

     

    #21272

    Günther
    Felgo Team

    Hi Edward,

    I’ve added your issue description to our bug tracker, so one of our developers can check the Firebase Plugin if everything works correctly.

    If you require immediate help for your project, we are happy to help you out as part of the included support of the Felgo Pro plans.

    Best,
    Günther

    #21274

    Edward

    Hi Gunther and thanks,

     

    Just a note firebase is working fine with reads/writes when my paths are known, or dynamic to a degree, but it’s the deleting and double nested data that isn’t working even when following your example? I’m sure it’s something wrong in my code somewhere :/

     

    Thanks and let me know if there was an issue your end!

    Edd

     

    #21294

    Edward

    Hi Gunther!

     

    Any news on the firebase plugin? Just as a test last night i set my realtimeValueKey: to my public branch (which i can .getValue) when logging in, and it receives no changes? even when I manually edit the value in my firebase console!

     

    Thanks

    Edd

    #21365

    Edward

    Hi Gunther,

     

    I was tweaking and looking at the code for the removal of the list entries,

    I was under the assumption the ‘id’ (unique time the entry was created, which is used at the Object.Key), is what the signal was deleting, not data within each Object!

    By adding another value into my JSON object of “creationDate” (matching the date which is the Key) deletion works perfectly!

     

    deeper nested JSON objects within my data are still not displayed (reference the example above), Is there a suggested way you would access this? So my list

    Thanks

    Edd

Viewing 5 posts - 1 through 5 (of 5 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support