HarmonyOS UI未在数据更新时刷新

列表数据生成了UI,当点击UI组件时bean中的select改变,期望是对应设置的Ui也随之改变。

@State optionalItemList: OptionalItemBean[] = []

interface OptionalItemBean {
  title: string,
  tag: string,
  select: boolean
}

@Builder
private optionalItemView(bean:OptionalItemBean){
  RelativeContainer() {
    Row() {
      Image(bean.select ? $r('app.media.ic_dui') : "")
        .width(18)
        .height(18)
        .backgroundColor(bean.select ? '#FFA69DFF' : Color.White)
        .borderRadius(6)
        .borderColor("#FFE8E5FC")
        .borderWidth(bean.select ? 0 : 2)
        .margin({ left: 12 })

      Text(bean.title)
        .fontSize(14)
        .fontColor('#FF333333')
        .margin({ left: 10 })
        .layoutWeight(1)
    }
    .width('100%')
    .height('100%')
    .alignItems(VerticalAlign.Center)

    Text(bean.tag)
      .fontSize(10)
      .fontColor('#FF333333')
      .visibility(TextUtil.isNotEmpty(bean.tag) ? Visibility.Visible : Visibility.Hidden)
      .padding({
        top: 2,
        bottom: 2,
        left: 6.5,
        right: 6,
      })
      .margin({ top: -9 })
      .linearGradient({
        angle: 45,
        colors: [['#FFFED647', 0], ['#FFFFD55E', 1]]
      })
      .borderRadius({
        topLeft: 5,
        topRight: 5,
        bottomLeft: 5,
        bottomRight: 0
      })
      .alignRules({
        top: { anchor: "__container__", align: VerticalAlign.Top },
        right: { anchor: "__container__", align: HorizontalAlign.End }
      })
  }
  .width("100%")
  .height(40)
  .backgroundColor(Color.White)
  .borderRadius(8)
  .onClick(() => {
    bean.select = !bean.select
  })
}
  • 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.
HarmonyOS
2025-01-09 13:19:32
3.4w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

有关@builder的使用及限制调节,可参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-builder-V5

分享
微博
QQ
微信
回复
2025-01-09 16:09:22
相关问题
HarmonyOS 更新数据UI刷新
1040浏览 • 1回复 待解决
HarmonyOS UI和ViewModel如何刷新数据
688浏览 • 1回复 待解决
HarmonyOS 下拉刷新的时候没有更新数据
1323浏览 • 1回复 待解决
【列表数据更新后页面不刷新
379浏览 • 1回复 待解决
在数据文件中写入数据的方法
1028浏览 • 1回复 待解决
修改ForEach使用的数据对象,UI刷新
2996浏览 • 1回复 待解决
HarmonyOS UI刷新
824浏览 • 1回复 待解决
HarmonyOS 主线程刷新UI
1152浏览 • 1回复 待解决
HarmonyOS Native怎么更新UI?
756浏览 • 1回复 待解决
HarmonyOS LazyForEach问题刷新UI问题
974浏览 • 1回复 待解决
HarmonyOS 卡片更新图片不刷新
873浏览 • 1回复 待解决
UI预览不会自动刷新, 且刷新较慢
1969浏览 • 1回复 待解决