Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewAnnouncements › FireBase -> JsonListModel

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #25360

    Alexander

    Hello, I’m trying to configure switching of a CategoryPage that is connected to the Realtime Database, I can only do it in one direction, I think I need to update the JsonListModel??? If so, please tell me how to do it correctly.

    import QtQuick.Controls
    import QtQuick.Layouts
    import QtQuick
    import Felgo

    App {

    property var shoppingItems: ({})

    property string dbKeyAllShoppingItems : “showcase”

    //create a model for a category

    function createModelForCategory(category)

    {

    dbKeyAllShoppingItems = category

    database.getValue(category)

    }

    // ————————————————————————————-
    // configuration FireBase
    FirebaseConfig {
    id: fbConfig
    }

    FirebaseDatabase {
    id: database

    config: fbConfig

    realtimeValueKeys: [dbKeyAllShoppingItems]

    onRealtimeValueChanged: (success, key, value) => {
    if(success && key === dbKeyAllShoppingItems) {
    shoppingItemsLoaded(value)
    }
    }

    onReadCompleted:(success, key, value) => {

    if(success && key === dbKeyAllShoppingItems) {
    shoppingItemsLoaded(value)

    }

    }

    }

    // Function that updates the internal data store whenever the values
    // changes in the Firebase database in real time.
    function shoppingItemsLoaded(value) {

    shoppingItems = value || {}

    }

    JsonListModel {
    id: jsonModel
    // readonly property var shoppingItem: dataModel.shoppingItems[modelData] || {}

    source: shoppingItems || {} //[modelData] || {}//Object(dataModelfareBase.shoppingItems)//(dataModelfareBase.shoppingItems)
    // keyField: “id”//dataModel.shoppingItems[modelData] || {}

    //Defines the available model fields. If not installed,
    //JsonListModel will use the first added entry as a reference.
    fields: [“title”,”text”,”name”]

    }

    Navigation {
    id: appNav
    navigationMode: navigationModeTabs
    anchors.fill: parent
    NavigationItem {
    title: qsTr(“showcase”)
    iconType: IconType.thlarge

    NavigationStack {
    id: navStack0
    CategoryPage {category: “showcase”}
    }
    }

    NavigationItem {
    title: qsTr(“catalog”)
    iconType: IconType.alignjustify//ellipsish

    NavigationStack {
    id: navStack4
    CategoryPage {category: “catalog”}

    }

    }

    }

    import QtQuick
    import Felgo
    import QtQuick.Controls
    AppPage {

    title: category
    property var category

    Component.onCompleted: {

    createModelForCategory(category)

    }

    AppListView {
    id:listView
    anchors.fill: parent
    model: jsonModel
    delegate: MyDelegate {

    }
    }

    }

     

    #25364

    Günther
    Felgo Team

    Hi,

    the JsonListModel does not care about the data source. Whenever the JsonListModel::source is updated to a new value, the model will reflect the new data. It does not matter if this data is previously retrieved from Firebase or somewhere else.

    You can find some examples that use JsonListModel in the Felgo SDK demos. For example the Todo List App: https://felgo.com/doc/felgo-appdemos-todo-list-example/

    Best,
    Günther

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

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded