Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to assign ListModel's data to JsonObj in JS

    General and Desktop
    2
    2
    473
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Anas A. Ismail last edited by p3c0

      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)
      

      }

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @Anas A. Ismail last edited by p3c0

        @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.

        157

        1 Reply Last reply Reply Quote 0
        • First post
          Last post