代码没有报错,但是页面没有交互

 ForEach(filterList, (item: string, index: number) => {
          Text(item)
            .fontColor(this.filterIndex == index ? Color.Red : Color.Gray)
            .fontSize(14)
            .padding({
              top: 5,
              bottom: 5,
              left: 10,
              right: 10
            })
            .backgroundColor('#f6f6f6')
            .borderRadius(5)
            .onClick(() => {
              // 记录点击索引
              this.filterIndex = index
              // 重置排序条件
              this.sortIndex = 0
              // 先筛选
              this.renderList = carList.filter((item => {
                if (index == 0) {
                  return true
                } else {
                  return item.type == index
                }

              }))
              // 再排序
              this.renderList = this.renderList.sort((a, b) => {
                switch (index) {
                  case 0:
                    return a.rank - b.rank
                  case 1:
                    return b.min_price - a.min_price
                  case 2:
                    return b.count - a.count
                  default:
                    return 0
                }
              })
            })
        })

 

  1. 检查 carList 数据是否正确加载:确保在执行排序操作之前,carList 已经正确获取到了数据。

  2. 数据绑定问题:确保 carList 的状态更改能够正确反映到界面上。在鸿蒙中,状态的更改有时需要特定的机制来触发界面更新。

  3. 检查 filterIndex 的值是否正确更改:在点击排序选项时,确认 filterIndex  的值确实按照预期进行了更新。

//解决办法,在 filterList 加了this

 ForEach(this.filterList, (item: string, index: number) => {
          Text(item)
            .fontColor(this.filterIndex == index ? Color.Red : Color.Gray)
            .fontSize(14)
            .padding({
              top: 5,
              bottom: 5,
              left: 10,
              right: 10
            })
            .backgroundColor('#f6f6f6')
            .borderRadius(5)
            .onClick(() => {
              // 记录点击索引
              this.filterIndex = index
              // 重置排序条件
              this.sortIndex = 0
              // 先筛选
              this.renderList = carList.filter((item => {
                if (index == 0) {
                  return true
                } else {
                  return item.type == index
                }

              }))
              // 再排序
              this.renderList = this.renderList.sort((a, b) => {
                switch (index) {
                  case 0:
                    return a.rank - b.rank
                  case 1:
                    return b.min_price - a.min_price
                  case 2:
                    return b.count - a.count
                  default:
                    return 0
                }
              })
            })
        })

      

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值