[Solved]Nested List Model Dynamic Data Population
-
Basically what I want to implement is populate list model
@ListModel {
id: nestedModel
}@to some thing like,
@nestedModel.append({
locationName: qsTr("Location5"),
collapsed: true,
folders: [{
folderName: qsTr("Cam11")
}, {
folderName: qsTr("Cam22")
}, {
folderName: qsTr("Cam33")
}, {
folderName: qsTr("Cam44")
}]
})nestedModel.append({ locationName: qsTr("Location1"), collapsed: true, folders: [{ folderName: qsTr("Cam11") }, { folderName: qsTr("Cam22") }, { folderName: qsTr("Cam33") }, { folderName: qsTr("Cam44") }] })@
and which works fine.
But I have to do both parent and child list separately. Here parent is "locationName" and child is "folders"
I can success fully update "locationName" using
@for(var i=0;i<locations.length;i++){
nestedModel.append({
locationName: locations[i],
collapsed: true
})
}@But how can I update "folders" in separate loop as I get the folders list after locations list.
I already tried like
@ListModel {
id:diractories
}diractories.clear(); for(var j=0;j<dirs.length;j++){ diractories.append({ folderName: dirs[j] }) console.log(diractories.get(j).folderName) }
nestedModel.set(list_view.currentIndex, {folders: diractories})@
Where I have added an extra item "folders" at the first time, like@nestedModel.append({
locationName: locations[i],
collapsed: true
folders:diractories
})@But all my "folders" list looks same for every "locationName".
So my question is how can add data for "folders" dynamically?
Thanks
Haris -
Sorry but i don't understand what you want. What is the problem, filling the model, or updating/repainting of the list element? Maybe post you source.
-
Finally I found the answer "here":http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView
I just used below code to append new data to child list,@nestedModel.get(index).folders.append({"folderName": "Cam55}) nestedModel.get(index).folders.append({"folderName": "Cam66})@
-
Please add [SOLVED] to your thread title if it's solved.