代码拉取完成,页面将自动刷新
// from yeyinglong, 19.06.2024
@Entry
@ComponentV2
struct ListItemGroupRepeat {
@Local message: string = 'Hello World';
@Local arr: Array<number> = []
@Local lanes: number = 1
aboutToAppear(): void {
for (let i = 0; i < 20; i++) {
this.arr.push(i)
}
}
build() {
Column() {
Row() {
Button('列数+1')
.onClick(() => {
this.lanes++
})
Button('列数-1')
.onClick(() => {
if (this.lanes > 1) {
this.lanes--
}
})
}
List() {
ListItemGroup({style:ListItemGroupStyle.CARD}) {
Repeat<number>(this.arr)
.virtualScroll({totalCount:this.arr.length})
.each((item: RepeatItem<number>) => {
ListItem({style:ListItemStyle.CARD}) {
Text("Group:0,Item:" + item.item.toString())
}
.onAppear(()=>{
console.log("LIST_TEST:Group0:onAppear:" + item.item)
})
.onDisAppear(()=>{
console.log("LIST_TEST:Group0:onDisAppear:" + item.item)
})
})
}
.divider({strokeWidth:1, startMargin:12, endMargin:12})
ListItemGroup({style:ListItemGroupStyle.CARD}) {
Repeat<number>(this.arr)
.virtualScroll({totalCount:this.arr.length})
.each((item: RepeatItem<number>) => {
ListItem({style:ListItemStyle.CARD}) {
Text("Group:1,Item:" + item.item.toString())
}
.onAppear(()=>{
console.log("LIST_TEST:Group1:onAppear:" + item.item)
})
.onDisAppear(()=>{
console.log("LIST_TEST:Group1:onDisAppear:" + item.item)
})
})
}
.divider({strokeWidth:1, startMargin:12, endMargin:12})
ListItemGroup({style:ListItemGroupStyle.CARD}) {
Repeat<number>(this.arr)
.virtualScroll({totalCount:this.arr.length})
.each((item: RepeatItem<number>) => {
ListItem({style:ListItemStyle.CARD}) {
Text("Group:2,Item:" + item.item.toString())
}
.onAppear(()=>{
console.log("LIST_TEST:Group2:onAppear:" + item.item)
})
.onDisAppear(()=>{
console.log("LIST_TEST:Group2:onDisAppear:" + item.item)
})
})
}
.divider({strokeWidth:1, startMargin:12, endMargin:12})
}.backgroundColor(0xDCDCDC)
.height('100%')
.width('100%')
.cachedCount(3)
.lanes(this.lanes)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。