From 6066304d46949d5832f6e08e18793e72a3b03921 Mon Sep 17 00:00:00 2001 From: 189******51 Date: Wed, 30 Aug 2023 09:34:51 +0000 Subject: [PATCH] =?UTF-8?q?IssueNo:=20#I7X5WW:[=E6=96=B0=E9=9C=80=E6=B1=82?= =?UTF-8?q?]:=20Rectify=20the=20arkts=20syntax=20of=20qs=20on=20monthly=20?= =?UTF-8?q?Description:=20Rectify=20the=20arkts=20syntax=20of=20qs=20on=20?= =?UTF-8?q?monthly=20Sig:=20SIG=5FApplicaitonFramework=20Feature=20or=20Bu?= =?UTF-8?q?gfix:=20Feature=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 189******51 --- .../application-dev/quick-start/arkts-prop.md | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/zh-cn/application-dev/quick-start/arkts-prop.md b/zh-cn/application-dev/quick-start/arkts-prop.md index 171f1fb43b..fe4f7ebda4 100644 --- a/zh-cn/application-dev/quick-start/arkts-prop.md +++ b/zh-cn/application-dev/quick-start/arkts-prop.md @@ -419,7 +419,7 @@ class Book { @Component struct ReaderComp { - @Prop book: Book; + @Prop book: Book = new Book("", 1); build() { Row() { @@ -442,10 +442,10 @@ struct Library { ReaderComp({ book: this.allBooks[2] }) Divider() Text('Books on loaan to a reader') - ForEach(this.allBooks, book => { + ForEach(this.allBooks, (book: Book) => { ReaderComp({ book: book }) }, - book => book.id) + (book: Book) => book.id.toString()) Button('Add new') .onClick(() => { this.allBooks.push(new Book("The C++ Standard Library", 512)); @@ -579,6 +579,26 @@ class ClassB { 以下组件层次结构呈现的是@Prop嵌套场景的数据结构。 ```ts +// 以下是嵌套类对象的数据结构。 +@Observed +class ClassA { + public title: string; + + constructor(title: string) { + this.title = title; + } +} + +@Observed +class ClassB { + public name: string; + public a: ClassA; + + constructor(name: string, a: ClassA) { + this.name = name; + this.a = a; + } +} @Entry @Component @@ -588,10 +608,10 @@ struct Parent { build() { Column() { Button('change') - .onClick(() => { - this.votes.name = "aaaaa" - this.votes.a.title = "wwwww" - }) + .onClick(() => { + this.votes.name = "aaaaa" + this.votes.a.title = "wwwww" + }) Child({ vote: this.votes }) } @@ -600,33 +620,33 @@ struct Parent { @Component struct Child { - @Prop vote: ClassB + @Prop vote: ClassB = new ClassB('', new ClassA('')); build() { - Column() { + Column() { - Text(this.vote.name).fontSize(36).fontColor(Color.Red).margin(50) - .onClick(() => { - this.vote.name = 'Bye' - }) - Text(this.vote.a.title).fontSize(36).fontColor(Color.Blue) - .onClick(() => { - this.vote.a.title = "openHarmony" - }) - Child1({vote1:this.vote.a}) + Text(this.vote.name).fontSize(36).fontColor(Color.Red).margin(50) + .onClick(() => { + this.vote.name = 'Bye' + }) + Text(this.vote.a.title).fontSize(36).fontColor(Color.Blue) + .onClick(() => { + this.vote.a.title = "openHarmony" + }) + Child1({vote1:this.vote.a}) - } + } } } @Component struct Child1 { - @Prop vote1: ClassA + @Prop vote1: ClassA = new ClassA(''); build() { Column() { - Text(this.vote1.title).fontSize(36).fontColor(Color.Red).margin(50) - .onClick(() => { - this.vote1.title = 'Bye Bye' - }) + Text(this.vote1.title).fontSize(36).fontColor(Color.Red).margin(50) + .onClick(() => { + this.vote1.title = 'Bye Bye' + }) } } } -- GitLab