1

我有错误

ReferenceError: redRow 未定义

在这段代码上:

Repeater {
            property int redRow: 0
            ...
            Image {
                ...
                anchors.bottom: parent.bottom
                anchors.bottomMargin: height / 16 + height * redRow
                ...
            }

如果我把
property int redRow: 0

在文件的开头 - 好吧,为什么我没有机会把它放在中继器元素中?

4

1 回答 1

0

你可以把它放在中继器中,但你必须通过中继器的id来引用这个变量:

Repeater {
  id: repeater //add id to the repeater this can be any unique identifier
  property int redRow: 0
  ...
  Image {
    ...
    anchors.bottom: parent.bottom
    anchors.bottomMargin: height / 16 + height * repeater.redRow //reference repeaters property
    ...
  }
}
于 2013-01-06T09:38:02.027 回答