How to assign ListModel's data to JsonObj in JS



  • Hi everyone,
    How to assign ListModel's data to JsonObj in JS code to be saved to JSON file
    I made something like this

    ListModel{
    id: jsonDataModel;
    }
    JsonStorage{
    //registered type
    id: jsonStorage
    fileName: "db"
    }
    
    function savJSON()
    {
    var jsonObj = listModel // here's the problem, how this assignment could be made ?
    var data = JSON.stringify(jsonObj)
    jsonStorage.save(data)
    

    }


  • Moderators

    @Anas-A.-Ismail Assign the ListModel's id to that variable. Then you will need to iterate the model and stringify the individual data. Eg.:

    var model = jsonDataModel
    for(var a=0; a<model.count; a++) {
        console.log(JSON.stringify(model.get(a)))
    }
    

    Then you can somehow aggregate all the data into a single string and pass it to your function.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.