在嵌套委托中访问 modelData
Accessing modelData inside nested delegates
我有一个场景,我需要访问中继器内的模型数据,它是列表视图委托的一部分。我无法区分 listview 的 modelData 和 Repeater 的 modelData。
ListView
{
id: listViewData
model: listViewData //here listViewData is QObjectListModel
delegate:
ColumnLayout
{
Rectangle
{
TextArea
{
text: modelData.somePropertyA[index] // This works fine, no issues
....
}
Column
{
Repeater
{
id: repeaterData
model: modelData.getCount(modelData.somePropertyB[index]) // here modelData is referencing to listViewData's modelData.
Text
{
text: repeaterData.modelData.someFunction(listViewData.modelData)
//So my concern here is, how do i differently access listViewData's modelData and repeaterData's modelData. I tried referencing by using id name as you can see. But i am unable to use in this way, it says undefined.
}
}
}
}
}
}
您可以将外部模型数据绑定到某个委托 属性 以创建一种别名,例如:
Column {
spacing: 5
Repeater {
model: ["A","B","C"]
delegate: Row {
spacing: 5
property var storedValue: modelData
Repeater {
model: ["1","2","3"]
delegate: Text {
text: modelData + storedValue
}
}
}
}
}
我有一个场景,我需要访问中继器内的模型数据,它是列表视图委托的一部分。我无法区分 listview 的 modelData 和 Repeater 的 modelData。
ListView
{
id: listViewData
model: listViewData //here listViewData is QObjectListModel
delegate:
ColumnLayout
{
Rectangle
{
TextArea
{
text: modelData.somePropertyA[index] // This works fine, no issues
....
}
Column
{
Repeater
{
id: repeaterData
model: modelData.getCount(modelData.somePropertyB[index]) // here modelData is referencing to listViewData's modelData.
Text
{
text: repeaterData.modelData.someFunction(listViewData.modelData)
//So my concern here is, how do i differently access listViewData's modelData and repeaterData's modelData. I tried referencing by using id name as you can see. But i am unable to use in this way, it says undefined.
}
}
}
}
}
}
您可以将外部模型数据绑定到某个委托 属性 以创建一种别名,例如:
Column {
spacing: 5
Repeater {
model: ["A","B","C"]
delegate: Row {
spacing: 5
property var storedValue: modelData
Repeater {
model: ["1","2","3"]
delegate: Text {
text: modelData + storedValue
}
}
}
}
}