文档开发者中心
我的
|

HarmonyOS 5

嵌套ForEach不能自动适应高度

问题描述:

写了一个二维数组存放数据。用ForEach嵌套使用,当列表长度超过屏幕高度后,就会出现数据丢失(丢失一整个items),并且无法通过滚动显示丢失的数据。

收起
自动换行
深色代码主题
复制
ForEach(this.selectArr, (items) => { 
  Column() { 
    ForEach(items, (item) => { 
      Item({ obj: item }) 
    }, (item) => item.lable.toString()) 
  }.itemCardStyle() 
}, (items) => items.toString())
点赞
收藏
回复
1
分享
举报
浏览156 发布于2024-06-17 07:15北京
全部评论
最多点赞
最新发布
最早发布

解决方案:

请参考如下代码,

收起
自动换行
深色代码主题
复制
@Entry 
@Component 
struct objList { 
  private scrollerForScroll: Scroller = new Scroller() 
 
  build() { 
    Column() { 
      Text('我是标题') 
        .height(50) 
        .width('100%') 
      Scroll(this.scrollerForScroll) { 
        Column() { 
          ForEach([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 26, 28, 29, 30, 31], (item) => { 
            Row() { 
              Text(item.toString()).margin({ left: 8 }) 
 
            }.width('100%').height(48).padding({ left: 6.5, right: 2.5 }) 
          }, (item: string) => item.toString()) 
        } 
        .padding({ left: 12, right: 12 }) 
        .backgroundColor(Color.White) 
        .borderRadius(8) 
      }.layoutWeight(1) 
    } 
 
  } 
}
1楼回复于2024-06-17 07:16 来自北京
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。