如何获取嵌套Repeater中的父Repeater索引?

问题描述 投票:0回答:1

我遇到了以下问题:

Repeater {
    id: parentRepeater
    model: Array(10).fill([""])

    Repeater {
        model: modelData
        
        Label {
            text: index // gets only the child index, not parent
        }
    }
}

我想打印出父索引,但使用纯

index
它只显示子索引,这是应该的。

有没有办法让它显示父级的索引?

qt indexing qml qt6
1个回答
0
投票

我自己的解决方案如下,通过使

parentRepeaterIndex
属性具有父级
index
值:

Repeater {
    id: parentRepeater
    model: Array(10).fill([""])

    Repeater {
        model: modelData
        property int parentRepeaterIndex: index

        
        Label {
            text: parentRepeaterIndex
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.