我想访问ListItemComponent范围之外的imageContainer属性,例如当方向更改时,我尝试了以下内容:
imageContainer.imageHeight
它在日志中返回未定义的内容。
代码部分如下:
ListItemComponent {
type: "item"
Container {
id: listContainer
layout: DockLayout {
}
preferredWidth: 180
preferredHeight: 180
ActivityIndicator {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
id: myIndicator
preferredWidth: 70
}
Container {
id: webimageContainer
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
preferredWidth: 200
preferredHeight: 200
ImageDownloader {
id: imageContainer
imageWidth: 170
imageHeight: 170
imageUrl: ListItemData.thumbnailPath
onCloudImageUnavailable: {
imageUrl = "asset:///images/ic_view_image.png";
}
}
}
onCreationCompleted: {
if (parent.parent.dv_width == 720) {
listContainer.preferredWidth = 160;
listContainer.preferredHeight = 160;
}
}
}
}
提前致谢。
答案 0 :(得分:1)
在您的案例中向根组件ListItemComponent添加属性以访问其嵌套项:
ListItemComponent {
id: listItemComponent
property int imageContainerHeight: imageContainer.imageHeight
....
ImageDownloader {
id: imageContainer
}
...
}
所以你可以从外面访问这个属性:
console.log(listItemComponent.imageContainerHeight);