Currently, I have some JavaScript data that consists of a list of objects containing other objects and arrays, which I want to append to a ListModel.
This is what the structure looks like (assuming that the data is generated elsewhere and its structure should be avoided):
import QtQuick 2.0
Rectangle {
width: 600
height: 300
ListView {
anchors.fill: parent
model: ListModel {
id: listModel
}
delegate: Text {
text: 'key: '+ key + ', subdict["subkey1"]: ' + subdict.subkey1 +
', sublist.count: '+ sublist.count + ', sublist[0]: '+ sublist[0] +
', sublist.get(0): '+ sublist.get(0)
wrapMode: Text.WordWrap
width: parent.width
color: index % 2 == 0 ? "darkgreen" : "brown"
}
Component.onCompleted: {
var values = [
{'key': 'foo1', 'subdict': {'subkey1': 'subfoo1', 'subkey2': 'subbar1'},
'sublist': ['subvalue1', 'subvalue2']},
{'key': 'foo2', 'subdict': {'subkey1': 'subfoo2', 'subkey2': 'subbar2'},
'sublist': ['subvalue3', 'subvalue4', 'subvalue5']},
{'key': 'foo3', 'subdict': {'subkey1': 'subfoo3', 'subkey2': 'subbar4'},
'sublist': []}
]
for (var i in values)
listModel.append(values[i]);
}
}
}
Although most parts work fine, I am having trouble accessing the elements within sublist
. I can only retrieve the count of items since they are actually a new ListModel. It seems impossible to retrieve the actual content using something like sublist.get(0)
.
Could this be a bug, or am I overlooking something?