Hello Forum
I want to transform a static structure to a dynamic :
Example:
ListModel {
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
}
ListModel {
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
}
To copy to clipboard, switch view to plain text mode
Dynamic :
ListModel {
Component.onCompleted: {
for(var i = 0; i < 2; ++i) {
append({
"categoryName": "ABC",
"subItems": [
{"itemName": "aaa"},
{"itemName": "bbb"}
]
})
}
}
}
ListModel {
Component.onCompleted: {
for(var i = 0; i < 2; ++i) {
append({
"categoryName": "ABC",
"subItems": [
{"itemName": "aaa"},
{"itemName": "bbb"}
]
})
}
}
}
To copy to clipboard, switch view to plain text mode
Until here everything is good
My Question: How can I transform the below static structure to dynamic
ListModel {
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "DEF"
subItems: [
ListElement { itemName: "ccc"},
ListElement { itemName: "ddd"}
]
}
ListElement {
categoryName: "GHI"
subItems: [
ListElement { itemName: "eee"},
ListElement { itemName: "fff"},
ListElement { itemName: "ggg"}
]
}
}
ListModel {
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "DEF"
subItems: [
ListElement { itemName: "ccc"},
ListElement { itemName: "ddd"}
]
}
ListElement {
categoryName: "GHI"
subItems: [
ListElement { itemName: "eee"},
ListElement { itemName: "fff"},
ListElement { itemName: "ggg"}
]
}
}
To copy to clipboard, switch view to plain text mode
The problem is I don't know the size of SubItems !!
First : I get the projects (list of project)
Second : I get for each project list of files (list of files)
I want to present this structure :
project0
file1
file2
project1
file3
file4
project2
file5
file6
file7
I try this, not work well !
ListModel {
id: menuModel
Component.onCompleted: {
var listProjects = handledProjets()
for(var k=0; k<listProjects.length; k++)
{
var nameplugin = listProjects[k]
console.log(">>> Projet = "+nameplugin)
//menuModel.append({text:nameplugin})
//append({"categoryName": nameplugin})
var listFiles = handledFiles(nameplugin)
console.log(">>> File("+(l+1)+") = "+listFiles[l])
//mychild.append({text:listFiles[l]})
append({
"categoryName": nameplugin
"subItems": [
{"itemName": listFiles[l]}
]
})
}
}
ListModel {
id: menuModel
Component.onCompleted: {
var listProjects = handledProjets()
for(var k=0; k<listProjects.length; k++)
{
var nameplugin = listProjects[k]
console.log(">>> Projet = "+nameplugin)
//menuModel.append({text:nameplugin})
//append({"categoryName": nameplugin})
var listFiles = handledFiles(nameplugin)
console.log(">>> File("+(l+1)+") = "+listFiles[l])
//mychild.append({text:listFiles[l]})
append({
"categoryName": nameplugin
"subItems": [
{"itemName": listFiles[l]}
]
})
}
}
To copy to clipboard, switch view to plain text mode
Cheers;
Bookmarks