HarmonyOS 列表多选页面无法刷新

HarmonyOS
2024-12-25 14:31:58
1532浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

参考示例如下:

import { LinkedList } from '@kit.ArkTS';

@Entry
@Component
struct Index {
  @State arrayListMoodThing: dataEnty[][] =
    [[new dataEnty(0, '电影1', false), new dataEnty(1, '电影1', false), new dataEnty(2, '电影1', false),
      new dataEnty(3, '电影1', false), new dataEnty(4, '电影1', false), new dataEnty(5, '电影1', false)],
      [new dataEnty(6, '电影1', false), new dataEnty(7, '电影1', false), new dataEnty(8, '电影1', false),
        new dataEnty(9, '电影1', false), new dataEnty(10, '电影1', false), new dataEnty(11, '电影1', false)]];
  @State arrSelectedIds: Array<dataEnty> = new Array()

  build() {
    Column() {
      Swiper() {
        ForEach(this.arrayListMoodThing, (datas: dataEnty[], index: number) => {
          Grid() {
            ForEach(datas, (data: dataEnty, i: number) => {
              GridItem() {
                ViewA({
                  label: data.txt, data: data, onClickItem: (data) => {
                    this.arrSelectedIds.push(data)
                    console.log('this.arrSelectedIds----', JSON.stringify(this.arrSelectedIds))
                    if (this.arrSelectedIds.length > 3) {
                      let needChangeItem = this.arrSelectedIds[0]
                      this.arrSelectedIds.splice(0, 1)
                      for (let index = 0; index < this.arrayListMoodThing.length; index++) {
                        const element = this.arrayListMoodThing[index];
                        for (let index = 0; index < element.length; index++) {
                          const item = element[index];
                          if (item.id == needChangeItem.id) {
                            item.selected = false
                            item.txt = '电影1'
                          }
                        }
                      }
                    }

                  }
                })
              }
              .width(80)
              .height(80)
            });
          }
          .columnsTemplate('1fr 1fr 1fr')
          .rowsTemplate('1fr 1fr 1fr')
          .width('100%')
          .height('100%')
          .rowsGap(10)
          .columnsGap(10)
          .margin({ bottom: 20, right: 20, left: 20 });
        });
      }
      .width('100%')
      .height(300)
      .width('100%')
      .height('100%')
      .backgroundColor('#ffffff')
      .padding({ top: 10 })
    }
  }
}

@Observed
class dataEnty {
  txt: string = ""
  selected: boolean = false
  id: number = 0

  constructor(id: number, txt: string, sel: boolean) {
    this.id = id
    this.txt = txt
    this.selected = sel

  }
}

@Component
struct ViewA {
  // 子组件ViewA的@ObjectLink的类型是ClassA
  @ObjectLink data: dataEnty;
  label: string = 'ViewA1';
  /*选中的id*/

  onClickItem?: (item: dataEnty) => void

  build() {
    Row() {
      Button(` ${this.data ? this.data.txt : "undefined"}`)
        .margin(10)
        .onClick(() => {
          this.data.selected == true;
          this.data.txt = 'sss'
          if (this.onClickItem != undefined) {
            this.onClickItem(this.data)
          }

        })
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
分享
微博
QQ
微信
回复
2024-12-25 16:43:54
相关问题
HarmonyOS 列表中checkbox多选
528浏览 • 1回复 待解决
HarmonyOS webview加载页面无法显示
1745浏览 • 1回复 待解决
HarmonyOS hap跳hsp页面无法跳转
943浏览 • 1回复 待解决
HarmonyOS 分屏模式下页面无法滑动
644浏览 • 1回复 待解决
HarmonyOS scroll嵌套list页面无法滑动
1333浏览 • 1回复 待解决
HarmonyOS Har静态包内部页面无法跳转
1428浏览 • 1回复 待解决
列表数据更新后页面刷新
344浏览 • 1回复 待解决
HarmonyOS 列表刷新问题
1319浏览 • 1回复 待解决
HarmonyOS 通知列表刷新事件
710浏览 • 1回复 待解决
HarmonyOS ForEach列表刷新问题
909浏览 • 1回复 待解决