HarmonyOS List组件指定item刷新实现方案?

如题:HarmonyOS List组件指定item刷新实现方案?

阅读 420
1 个回答

参考示例代码:

@Entry
@Component
struct ListItemDemo {
  @State message: string = 'Hello World';
  @State list: number[] = []
  aboutToAppear(): void {
    this.list.push(1)
    this.list.push(2)
    this.list.push(3)
  }
  updateItem(){
    this.list[1]++
  }

  build() {
    Column() {
      Button('更改数据')
        .onClick(() => {
          this.updateItem()
        })
      List(){
        ForEach(this.list, (item:number) => {
          ListItem(){
            Row(){
              Text(item+ '')
            }
          }
        })
      }
    }
    .height('100%')
    .width('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进