将Group中的数据抽象成一个组件,在组件中传递Group所需的参数,示例代码如下:@Observed class ProjectArray extends Array<string>{ } @Observed class Subject { public title: string; public projects: ProjectArray; constructor(title, projects) { this.title = title; this.projects = projects; } } @Component struct ViewA { title: string; @ObjectLink projects: ProjectArray; build() { Column() { Text(this.title) List(){ ForEach(this.projects, (project) => { ListItem() { Text(project) .width("100%").height(100).fontSize(20) .textAlign(TextAlign.Center).backgroundColor(0xFFFFFF) } }) } } } } @Entry @Component struct ListItemGroupExample2 { @State timetable: Subject[] = [ new Subject('星期一', new ProjectArray('语文', '数学', '英语')) ] build() { Column() { Button('change') .onClick(() => { console.log('testTag: Change'); this.timetable[0].projects.splice(0, 1, '英语'); }) ForEach(this.timetable, (table) => { ViewA({title: table.title, projects: table.projects}) }) }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 20 }) } }本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。
将Group中的数据抽象成一个组件,在组件中传递Group所需的参数,示例代码如下:
本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。