鸿蒙 Repeat V2的懒加载
·
比lazyForEach 简单
@Entry
@ComponentV2
struct RepeatPage {
@Local listData: string[] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
build() {
Column() {
List({space : 10}){
Repeat<string>(this.listData)
.each((repeatItem)=>{
//这里需要手动打 提示不出来
ListItem(){
Text(repeatItem.item)
.width('100%')
.height(300)
.backgroundColor(Color.Pink)
.textAlign(TextAlign.Center)
}
})
.virtualScroll({totalCount:this.listData.length})
.key((item,index)=>{
return item
})
.templateId((item,index)=>{
return index%2 ===0 ?'':'aaa'
})
//自定义模板 默认样式为''
.template('aaa',(repeatItem : RepeatItem<string>)=>{
ListItem(){
Text(repeatItem.item)
.width('100%')
.height(300)
.backgroundColor(Color.White)
.textAlign(TextAlign.Center)
}
},{cachedCount : 1})
}.cachedCount(4)
}
.height('100%')
.width('100%')
}
}
更多推荐


所有评论(0)