Reputation: 6942
I'm looking for code sample to collapse/expand ListItem
in QML.
Currently I have an idea to do it through toggling visible
flag for each child of triggered item. But I can't imagine how to iterate the children. Here is piece of code:
ListView {
dataModel: XmlDataModel {...}
onTriggered: {
var dataType = dataModel.itemType(indexPath)
if (dataType == "header")
{
var childrenCount = dataModel.childCount(indexPath);
for (int i = 0; i < childrenCount; i++)
{
// what to write here to get each child ListItem?
}
}
}
}
Thanks in advance.
PS: There is a sample for my task where we inherit from bb::cascades::DataModel
and override childCount
. But I would like to not deal with C++ classes.
Upvotes: 2
Views: 689
Reputation: 4961
Perhaps you could consider setting a visible property in the dataModel
and binding the visibility of the children to it.
ListView {
dataModel: XmlDataModel {...}
...
listItemComponents: [
ListItemComponent {
visible: ListItemData.visible
...
}
]
}
Then to loop through the children and make them all invisible you could just loop through the dataModel
.
Upvotes: 1