如何为中继器中的属性创建别名? [英] How can I create an alias to a property within a Repeater?

查看:53
本文介绍了如何为中继器中的属性创建别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码:

Repeater {
    id: myImageArr
    property alias changeSource: imageElement
    model: 3
    Image {
        id: imageElement
    }
}

给我一​​个错误:

无效的别名引用.无法找到 IDimageElement"

Invalid alias reference. Unable to find id "imageElement"

推荐答案

repeater 里面的Image是根据模型动态创建的,所以不能直接通过id引用.如果您的模型是固定值 (3),那么您可以使用 Repeater.itemAt(index) 函数.例如,为repeater创建的第一个Image创建别名:

The Image inside the repeater is dynamically created depending on the model, so you can't refer it directly by id. If your model is a fixed value (3), then you can access the Image instance by using Repeater.itemAt(index) function. For example, to create alias to the first Image created by repeater:

property alias changeSource: myImageArr.itemAt(0)

这篇关于如何为中继器中的属性创建别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆