QML Repeater获取当前序列
QML Repeater无法直接获取当前序列,但可以通过使用JavaScript来实现。
首先,在Repeater中添加一个属性来保存当前序列:
Repeater {
id: myRepeater
property int currentIndex: -1 // 初始化为-1,表示未开始循环
model: myModel
delegate: myDelegate
}
然后,在delegate中使用JavaScript来更新currentIndex属性:
Component {
id: myDelegate
Item {
// ...
Component.onCompleted: {
myRepeater.currentIndex = index // 更新currentIndex为当前序列
}
}
}
现在,可以通过访问myRepeater.currentIndex来获取当前序列。注意,currentIndex从0开始计数
原文地址: http://www.cveoy.top/t/topic/eQUc 著作权归作者所有。请勿转载和采集!