PDA

View Full Version : How to assign ListModel's data to JsonObj in JS



aIsmail
18th November 2015, 16:44
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)
}

anda_skoa
18th November 2015, 20:01
You probably have to iterate over the model entries and create a JS array containing the entries.

Or you implement a model that can deal with the JSON directly, i.e. a bit like XmlListModel.

Cheers,
_