二维数组循环渲染
Struct Parent {
@state simpleList:Array<Array<test>>=[
[new test('A相1','231'),new test('A相2',"231")],
[new test('B相1','231'),new test('B相2''232'),new test('B相3','231')],
[new test('C相1','233'),new test('A相2','231')]
];
build() {
Row() {
Column(){
ForEach(this.simpleList, (item: Array<test>,index:number)=>{ ForEach(item,(objItem: test, index: number) => { Text(objItem.name)
},(objItem:string,index:number)=> objItem)
},(item:string,index:number)=> item)
}
.width('100%')
.height('100%')
}
.height('100%')
循环里面一定要写index:number 不然渲染不全,查阅官方文档,ForEach里面的key需要不唯一,但是用自定义的key,如果你的item数据每个不一样的话,有id的话,这个item的key 就是唯一的了,index传进去里面循环自动给key唯一了,具体如图:
解决方案
不管index 有没有使用,都传一下,然后自己定义key,因为里面index自动执行唯一了