嵌套ForEach不能自动适应高度

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

ForEach(this.selectArr, (items) => { 
  Column() { 
    ForEach(items, (item) => { 
      Item({ obj: item }) 
    }, (item) => item.lable.toString()) 
  }.itemCardStyle() 
}, (items) => items.toString())
HarmonyOS
2024-06-03 22:01:44
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
flyCloud00

请参考如下代码,

@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) 
    } 
 
  } 
}
分享
微博
QQ
微信
回复
2024-06-04 21:33:18
相关问题
Web组件如何实现高度适应
421浏览 • 1回复 待解决
Grid组件如何实现高度适应
1355浏览 • 1回复 待解决
ForEach数组数据无法传输
3897浏览 • 1回复 待解决
ScrollView嵌套ListContainer
5160浏览 • 5回复 待解决
ForEach什么情况下会触发复用
309浏览 • 1回复 待解决
如何跳出ForEach,有人知道吗?
590浏览 • 1回复 待解决
ForEach在真机上无法执行
565浏览 • 1回复 待解决
软键盘弹出时,页面的自适应
402浏览 • 1回复 待解决
如何实现嵌套滚动技术
376浏览 • 1回复 待解决
Scroll与WaterFlow滑动嵌套
407浏览 • 1回复 待解决