QML 视图中的 Foreach 委托 [英] Foreach delegate in QML view
本文介绍了QML 视图中的 Foreach 委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用 foreach
或类似函数遍历 ListView
或 GridView
的委托?
Is it possible to iterate through the delegates of a ListView
or GridView
using foreach
or a similar function?
推荐答案
虽然 Simon 的回答是最佳实践,但要回答实际提出的问题,您需要遍历 的
的 children
ListViewcontentItem
像这样:
While Simon's answer is a best practice, to answer the actual question being asked you need to iterate over the children
of ListView
's contentItem
like so:
ListView {
id: list
model: mymodel
delegate: Text {
objectName: "text"
text: name + ": " + number
}
}
for(var child in list.contentItem.children) {
console.log(list.contentItem.children[child].objectName)
}
然后您可以使用 objectName 或委托项的任何其他属性进行过滤.
You can then filter using objectName or any other property of the delegate Item.
这篇关于QML 视图中的 Foreach 委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文