HarmonyOS 鸿蒙Next列表局部刷新
HarmonyOS 鸿蒙Next列表局部刷新
列表局部刷新
关于HarmonyOS 鸿蒙Next列表局部刷新的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
示例代码
[@Entry](/user/Entry)
[@Component](/user/Component)
struct Index {
[@State](/user/State) dataList: dataListItem[] = [];
aboutToAppear() {
for (let i = 0; i < 5; i++) { let dataItem = new dataListItem(${i * <span class="hljs-number"><span class="hljs-number">10</span></span>}
, “张三” + i) this.dataList.push(dataItem) }
}
build() {
Row() {
Column() {
List({ space: 8 }) {
ForEach(this.dataList, (item: dataListItem) => {
ListItem() {
ViewA({ dataItem: item })
}
}, (item: dataListItem) => item.name)
}
}.width(‘100%’)
}.height(‘100%’)
}
}
@Component
struct ViewA {
// 子组件ViewA的@ObjectLink的类型是ClassA
@ObjectLink dataItem: dataListItem;
build() {
Row() { Text(this.dataItem.name).layoutWeight(1) Text(this.dataItem.score).layoutWeight(1) }
.onClick(() => {
this.dataItem.score = “100”
})
.borderRadius(8)
.height(60)
.width(“100%”)
.backgroundColor(Color.Pink)
}
}
@Observed
class dataListItem {
score: string
name: string
constructor(score: string, name: string) {
this.score = score
this.name = name
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
参考链接
this.dataItem.score = "100"
这个要是放在父控件呢怎么实现刷新啊