source
stringlengths
14
113
code
stringlengths
10
21.3k
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Info { public info: MyMap<number, string>; constructor(info: MyMap<number, string>) { this.info = info; } } @Observed export class MyMap<K, V> extends Map<K, V> { public name: string; constructor(name?: string, args?: [K, V][]) { super(args); this.name = name ? name : "My Map";...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Info { public info: MySet<number>; constructor(info: MySet<number>) { this.info = info; } } @Observed export class MySet<T> extends Set<T> { public name: string; constructor(name?: string, args?: T[]) { super(args); this.name = name ? name : "My Set"; } getName() { ret...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Source { public source: number; constructor(source: number) { this.source = source; } } @Observed class Data { public data: number; constructor(data: number) { this.data = data; } } @Entry @Component struct Parent { @State count: Source | Data | undefined = new Source(10); b...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Info { public info: number = 0; constructor(info: number) { this.info = info; } } @Component struct ObjectLinkChild { @ObjectLink testNum: Info; build() { Text(`ObjectLinkChild testNum ${this.testNum.info}`) .onClick(() => { // The @ObjectLink decorated variable cannot...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Info { public info: number = 0; constructor(info: number) { this.info = info; } } @Component struct ObjectLinkChild { @ObjectLink testNum: Info; build() { Text(`ObjectLinkChild testNum ${this.testNum.info}`) .onClick(() => { // You can assign values to the properties o...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
class Parent { parentId: number; constructor(parentId: number) { this.parentId = parentId; } getParentId(): number { return this.parentId; } setParentId(parentId: number): void { this.parentId = parentId; } } class Child { childId: number; constructor(childId: number) { this.child...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
class Parent { parentId: number; constructor(parentId: number) { this.parentId = parentId; } getParentId(): number { return this.parentId; } setParentId(parentId: number): void { this.parentId = parentId; } } @Observed class Child { childId: number; constructor(childId: number) { ...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
let nextId = 1; @Observed class SubCounter { counter: number; constructor(c: number) { this.counter = c; } } @Observed class ParentCounter { id: number; counter: number; subCounter: SubCounter; incrCounter() { this.counter++; } incrSubCounter(c: number) { this.subCounter.counter += c; } ...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
CounterComp({ value: this.counter[0] }); // ParentComp passes ParentCounter to CounterComp. @ObjectLink value: ParentCounter; // @ObjectLink receives ParentCounter. // CounterChild is a child component of CounterComp. CounterComp passes this.value.subCounter to the CounterChild component. CounterChild({ subValue: this...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
let nextId = 1; @Observed class SubCounter { counter: number; constructor(c: number) { this.counter = c; } } @Observed class ParentCounter { id: number; counter: number; subCounter: SubCounter; incrCounter() { this.counter++; } incrSubCounter(c: number) { this.subCounter.counter += c;...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
let nextId = 1; @Observed class SubCounter { counter: number; constructor(c: number) { this.counter = c; } } @Observed class ParentCounter { id: number; counter: number; subCounter: SubCounter; incrCounter() { this.counter++; } incrSubCounter(c: number) { this.subCounter.counter += c;...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Component struct CounterComp { @Prop value: ParentCounter = new ParentCounter(0); @Prop subValue: SubCounter = new SubCounter(0); build() { Column({ space: 10 }) { Text(`this.subValue.counter: ${this.subValue.counter}`) .fontSize(20) .onClick(() => { this.subValue.counter += 7...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
let nextId = 1; @Observed class SubCounter { counter: number; constructor(c: number) { this.counter = c; } } @Observed class ParentCounter { id: number; counter: number; subCounter: SubCounter; incrCounter() { this.counter++; } incrSubCounter(c: number) { this.subCounter.counter += c; ...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class RenderClass { waitToRender: boolean = false; constructor() { setTimeout(() => { this.waitToRender = true; console.log("Change the value of waitToRender to" + this.waitToRender); }, 1000) } } @Entry @Component struct Index { @State @Watch('renderClassChange') renderClass: Re...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class RenderClass { waitToRender: boolean = false; constructor() { } } @Entry @Component struct Index { @State @Watch('renderClassChange') renderClass: RenderClass = new RenderClass(); renderClassChange() { console.log("The value of renderClass is changed to" + this.renderClass.waitToRender);...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Person { name: string = ''; age: number = 0; constructor(name: string, age: number) { this.name = name; this.age = age; } } @Observed class Info { person: Person; constructor(person: Person) { this.person = person; } } @Entry @Component struct Parent { @State @Watch('onCh...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
Child({ per: this.info.person, clickEvent: () => { console.log(':::clickEvent before', this.info.person.name); // 1 this.info.person.name = 'Jack'; console.log(':::clickEvent after', this.info.person.name); // 3 } })
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Weather { temperature:number; constructor(temperature:number) { this.temperature = temperature; } static increaseTemperature(weather:Weather) { weather.temperature++; } } class Day { weather:Weather; week:string; constructor(weather:Weather, week:string) { this.weather = w...
application-dev\ui\state-management\arkts-observed-and-objectlink.md
@Observed class Weather { temperature:number; constructor(temperature:number) { this.temperature = temperature; } static increaseTemperature(weather:Weather) { weather.temperature++; } } class Day { weather:Weather; week:string; constructor(weather:Weather, week:string) { this.weather = w...
application-dev\ui\state-management\arkts-page-custom-components-lifecycle.md
// Index.ets import { router } from '@kit.ArkUI'; @Entry @Component struct MyComponent { @State showChild: boolean = true; @State btnColor: string = "#FF007DFF"; // Only components decorated by @Entry can call the lifecycle callbacks of a page. onPageShow() { console.info('Index onPageShow'); } // On...
application-dev\ui\state-management\arkts-page-custom-components-lifecycle.md
// Page.ets @Entry @Component struct Page { @State textColor: Color = Color.Black; @State num: number = 0; // Only components decorated by @Entry can call the lifecycle callbacks of a page. onPageShow() { this.num = 5; } // Only components decorated by @Entry can call the lifecycle callbacks of a page...
application-dev\ui\state-management\arkts-page-custom-components-lifecycle.md
// Index.ets import { uiObserver, router, UIObserver } from '@kit.ArkUI'; @Entry @Component struct Index { listener: (info: uiObserver.RouterPageInfo) => void = (info: uiObserver.RouterPageInfo) => { let routerInfo: uiObserver.RouterPageInfo | undefined = this.queryRouterPageInfo(); if (info.pageId == router...
application-dev\ui\state-management\arkts-persiststorage.md
// EntryAbility.ets onWindowStageCreate(windowStage: window.WindowStage): void { windowStage.loadContent('pages/Index', (err) => { if (err.code) { return; } PersistentStorage.persistProp('aProp', 47); }); }
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp('aProp', 47);
application-dev\ui\state-management\arkts-persiststorage.md
AppStorage.get<number>('aProp'); // returns 47
application-dev\ui\state-management\arkts-persiststorage.md
@StorageLink('aProp') aProp: number = 48;
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp('aProp', 47); @Entry @Component struct Index { @State message: string = 'Hello World'; @StorageLink('aProp') aProp: number = 48; build() { Row() { Column() { Text(this.message) // The current result is saved when the application exits. After the restart, t...
application-dev\ui\state-management\arkts-persiststorage.md
let aProp = AppStorage.setOrCreate('aProp', 47); PersistentStorage.persistProp('aProp', 48);
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp('aProp', 48); if (AppStorage.get('aProp') > 50) { // If the value stored in PersistentStorage exceeds 50, set the value to 47. AppStorage.setOrCreate('aProp',47); }
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp("P", undefined); @Entry @Component struct TestCase6 { @StorageLink("P") p: number | undefined | null = 10; build() { Row() { Column() { Text(this.p + "") .fontSize(50) .fontWeight(FontWeight.Bold) Button("changeToNumber").onClick(() => { ...
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp("persistedDate", new Date()); @Entry @Component struct PersistedDate { @StorageLink("persistedDate") persistedDate: Date = new Date(); updateDate() { this.persistedDate = new Date(); } build() { List() { ListItem() { Column() { Text(`Persisted Dat...
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp("persistedMapString", new Map<number, string>([])); @Entry @Component struct PersistedMap { @StorageLink("persistedMapString") persistedMapString: Map<number, string> = new Map<number, string>([]); persistMapString() { this.persistedMapString = new Map<number, string>([[3, "one"]...
application-dev\ui\state-management\arkts-persiststorage.md
PersistentStorage.persistProp("persistedSet", new Set<number>([])); @Entry @Component struct PersistedSet { @StorageLink("persistedSet") persistedSet: Set<number> = new Set<number>([]); persistSet() { this.persistedSet = new Set<number>([33, 1, 3]); } clearSet() { this.persistedSet.clear(); } bu...
application-dev\ui\state-management\arkts-prop.md
// Simple type @Prop count: number; // The value change can be observed. this.count = 1; // Complex type @Prop title: Model; // The value change can be observed. this.title = new Model('Hi');
application-dev\ui\state-management\arkts-prop.md
class Info { public value: string; constructor(value: string) { this.value = value; } } class Model { public value: string; public info: Info; constructor(value: string, info: Info) { this.value = value; this.info = info; } } @Prop title: Model; // The value changes at the first layer can be ...
application-dev\ui\state-management\arkts-prop.md
// Assume that the object decorated by @State is an array. @Prop title: string[]; // The value change of the array itself can be observed. this.title = ['1']; // The value change of array items can be observed. this.title[0] = '2'; // The deletion of array items can be observed. this.title.pop(); // The addition of arr...
application-dev\ui\state-management\arkts-prop.md
@Component struct DateComponent { @Prop selectedDate: Date = new Date(''); build() { Column() { Button('child update the new date') .margin(10) .onClick(() => { this.selectedDate = new Date('2023-09-09'); }) Button(`child increase the year by 1`).onClick(() => { ...
application-dev\ui\state-management\arkts-prop.md
@Component struct CountDownComponent { @Prop count: number = 0; costOfOneAttempt: number = 1; build() { Column() { if (this.count > 0) { Text(`You have ${this.count} Nuggets left`) } else { Text('Game over!') } // Changes to the @Prop decorated variables are not synchr...
application-dev\ui\state-management\arkts-prop.md
@Component struct Child { @Prop value: number = 0; build() { Text(`${this.value}`) .fontSize(50) .onClick(() => { this.value++; }) } } @Entry @Component struct Index { @State arr: number[] = [1, 2, 3]; build() { Row() { Column() { Child({ value: this.arr[0] }...
application-dev\ui\state-management\arkts-prop.md
class Book { public title: string; public pages: number; public readIt: boolean = false; constructor(title: string, pages: number) { this.title = title; this.pages = pages; } } @Component struct ReaderComp { @Prop book: Book = new Book("", 0); build() { Row() { Text(this.book.title) ...
application-dev\ui\state-management\arkts-prop.md
let nextId: number = 1; // @Observed class Book { public id: number; public title: string; public pages: number; public readIt: boolean = false; constructor(title: string, pages: number) { this.id = nextId++; this.title = title; this.pages = pages; } } @Component struct ReaderComp { @Prop b...
application-dev\ui\state-management\arkts-prop.md
@Observed class Book { public id: number; public title: string; public pages: number; public readIt: boolean = false; constructor(title: string, pages: number) { this.id = nextId++; this.title = title; this.pages = pages; } }
application-dev\ui\state-management\arkts-prop.md
@Component struct MyComponent { @Prop customCounter: number; @Prop customCounter2: number = 5; build() { Column() { Row() { Text(`From Main: ${this.customCounter}`).fontColor('#ff6b6565').margin({ left: -110, top: 12 }) } Row() { Button('Click to change locally !') ...
application-dev\ui\state-management\arkts-prop.md
// The following is the data structure of a nested class object. @Observed class Son { public title: string; constructor(title: string) { this.title = title; } } @Observed class Father { public name: string; public son: Son; constructor(name: string, son: Son) { this.name = name; this.son = s...
application-dev\ui\state-management\arkts-prop.md
@Entry @Component struct Person { @State person: Father = new Father('Hello', new Son('world')); build() { Column() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Button('change Father name') .width(312) .height(40) .margin(12) ...
application-dev\ui\state-management\arkts-prop.md
@Component struct Child { @Prop value: Map<number, string> = new Map([[0, "a"], [1, "b"], [3, "c"]]); build() { Column() { ForEach(Array.from(this.value.entries()), (item: [number, string]) => { Text(`${item[0]}`).fontSize(30) Text(`${item[1]}`).fontSize(30) Divider() }) ...
application-dev\ui\state-management\arkts-prop.md
@Component struct Child { @Prop message: Set<number> = new Set([0, 1, 2, 3, 4]); build() { Column() { ForEach(Array.from(this.message.entries()), (item: [number, string]) => { Text(`${item[0]}`).fontSize(30) Divider() }) Button('init set').onClick(() => { this.message ...
application-dev\ui\state-management\arkts-prop.md
class Animals { public name: string; constructor(name: string) { this.name = name; } } @Component struct Child { @Prop animal: Animals | undefined; build() { Column() { Text(`Child's animal is ${this.animal instanceof Animals ? this.animal.name : 'undefined'}`).fontSize(30) Button('Ch...
application-dev\ui\state-management\arkts-prop.md
@Observed class Commodity { public price: number = 0; constructor(price: number) { this.price = price; } } @Component struct PropChild { @Prop fruit: Commodity; // The state variable is not initialized locally. build() { Text(`PropChild fruit ${this.fruit.price}`) .onClick(() => { thi...
application-dev\ui\state-management\arkts-prop.md
@Observed class Commodity { public price: number = 0; constructor(price: number) { this.price = price; } } @Component struct PropChild1 { @Prop fruit: Commodity; // The state variable is not initialized locally. build() { Text(`PropChild1 fruit ${this.fruit.price}`) .onClick(() => { t...
application-dev\ui\state-management\arkts-prop.md
class Score { value: number; constructor(value: number) { this.value = value; } static changeScore1(param1:Score) { param1.value += 1; } } @Entry @Component struct Parent { @State score: Score = new Score(1); build() { Column({space:8}) { Text(`The value in Parent is ${this.score.valu...
application-dev\ui\state-management\arkts-prop.md
class Score { value: number; constructor(value: number) { this.value = value; } static changeScore1(score:Score) { score.value += 1; } } @Entry @Component struct Parent { @State score: Score = new Score(1); build() { Column({space:8}) { Text(`The value in Parent is ${this.score.value}...
application-dev\ui\state-management\arkts-provide-and-consume.md
// Binding through the same variable name @Provide age: number = 0; @Consume age: number; // Binding through the same variable alias @Provide('a') id: number = 0; @Consume('a') age: number;
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume selectedDate: Date; build() { Column() { Button(`child increase the day by 1`) .onClick(() => { this.selectedDate.setDate(this.selectedDate.getDate() + 1) }) Button('child update the new date') .margin(10) .onClick(() => {...
application-dev\ui\state-management\arkts-provide-and-consume.md
// Incorrect format. An error is reported during compilation. let change: number = 10; @Provide(change) message: string = 'Hello'; // Correct format. let change: string = 'change'; @Provide(change) message: string = 'Hello';
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume msg: string; // Incorrect format. Local initialization is not allowed. @Consume msg1: string = 'Hello'; build() { Text(this.msg) } } @Entry @Component struct Parent { @Provide message: string = 'Hello'; build() { Column() { ...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume num: number; build() { Column() { Text(`Value of num: ${this.num}`) } } } @Entry @Component struct Parent { @Provide num: number = 10; build() { Column() { Text(`Value of num: ${this.num}`) Child() } ...
application-dev\ui\state-management\arkts-provide-and-consume.md
// Incorrect format. "a" is defined repeatedly. @Provide('a') count: number = 10; @Provide('a') num: number = 10; // Correct format. @Provide('a') count: number = 10; @Provide('b') num: number = 10;
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume num: number; build() { Column() { Text(`Value of num: ${this.num}`) } } } @Entry @Component struct Parent { // Incorrect format. @Provide is missing. num: number = 10; build() { Column() { Text(`Value of num: ${thi...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume num: number; build() { Column() { Text(`Value of num: ${this.num}`) } } } @Entry @Component struct Parent { // Correct format. @Provide num: number = 10; build() { Column() { Text(`Value of num: ${this.num}`) ...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct ToDoItem { // The @Consume decorated variable is bound to the @Provide decorated variable in its ancestor component ToDo under the same attribute name. @Consume count: number; build() { Column() { Text(`count(${this.count})`) Button(`count(${this.count}), count + 1`) .on...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume message: Map<number, string> build() { Column() { ForEach(Array.from(this.message.entries()), (item: [number, string]) => { Text(`${item[0]}`).fontSize(30) Text(`${item[1]}`).fontSize(30) Divider() }) Button('Consume init map').onClic...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { @Consume message: Set<number> build() { Column() { ForEach(Array.from(this.message.entries()), (item: [number, string]) => { Text(`${item[0]}`).fontSize(30) Divider() }) Button('Consume init set').onClick(() => { this.message = new Set([0, 1, ...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct Child { // The @Consume decorated variable is bound to the @Provide decorated variable in its ancestor component Ancestors under the same attribute name. @Consume count: string | undefined; build() { Column() { Text(`count(${this.count})`) Button(`count(${this.count}), Child`) ...
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct MyComponent { @Provide({allowOverride : "reviewVotes"}) reviewVotes: number = 10; }
application-dev\ui\state-management\arkts-provide-and-consume.md
@Component struct GrandSon { // The @Consume decorated variable is bound to the @Provide decorated variable in its ancestor component under the same attribute name. @Consume("reviewVotes") reviewVotes: number; build() { Column() { Text(`reviewVotes(${this.reviewVotes})`) // The Text component displays ...
application-dev\ui\state-management\arkts-provide-and-consume.md
class Tmp { a: string = '' } @Entry @Component struct HomePage { @Builder builder2($$: Tmp) { Text(`${$$.a}test`) } build() { Column() { CustomWidget() { CustomWidgetChild({ builder: this.builder2 }) } } } } @Component struct CustomWidget { @Provide('a') a: string = 'abc...
application-dev\ui\state-management\arkts-provide-and-consume.md
class Tmp { name: string = '' } @Entry @Component struct HomePage { @Provide('name') name: string = 'abc'; @Builder builder2($$: Tmp) { Text (`${$$.name}test`) } build() { Column() { Button('Hello').onClick(() => { if (this.name == 'ddd') { this.name = 'abc'; } els...
application-dev\ui\state-management\arkts-provide-and-consume.md
class Animal { name:string; type:string; age: number; constructor(name:string, type:string, age:number) { this.name = name; this.type = type; this.age = age; } static changeName(animal:Animal) { animal.name = 'Jack'; } static changeAge(animal:Animal) { animal.age += 1; } } @Entr...
application-dev\ui\state-management\arkts-provide-and-consume.md
class Animal { name:string; type:string; age: number; constructor(name:string, type:string, age:number) { this.name = name; this.type = type; this.age = age; } static changeName(animal:Animal) { animal.name = 'Jack'; } static changeAge(animal:Animal) { animal.age += 1; } } @Entr...
application-dev\ui\state-management\arkts-rendering-control-contentslot.md
abstract class Content { }
application-dev\ui\state-management\arkts-rendering-control-contentslot.md
import { nativeNode } from'libNativeNode.so' // The so. file implemented by you. import { NodeContent } from '@kit.ArkUI' @Entry @Component struct Parent { private nodeContent: Content = new NodeContent(); aboutToAppear() { // Create a node through the C API and add it to the nodeContent manager. ...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct Parent { @State simpleList: Array<string> = ['one', 'two', 'three']; build() { Row() { Column() { ForEach(this.simpleList, (item: string) => { ChildItem({ item: item }) }, (item: string) => item) } .width('100%') .height('100%') } ...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct Parent { @State simpleList: Array<string> = ['one', 'two', 'two', 'three']; build() { Row() { Column() { ForEach(this.simpleList, (item: string) => { ChildItem({ item: item }) }, (item: string) => item) } .width('100%') .he...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct Parent { @State simpleList: Array<string> = ['one', 'two', 'three']; build() { Row() { Column() { Text('Change Value of Third Array Item') .fontSize(24) .fontColor(Color.Red) .onClick(() => { this.simpleList[2] = 'new three'; ...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct ArticleList { @State simpleList: Array<number> = [1, 2, 3, 4, 5]; build() { Column() { ForEach(this.simpleList, (item: number) => { ArticleSkeletonView() .margin({ top: 20 }) }, (item: number) => item.toString()) } .padding(20) .width('100%') ...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
class Article { id: string; title: string; brief: string; constructor(id: string, title: string, brief: string) { this.id = id; this.title = title; this.brief = brief; } } @Entry @Component struct ArticleListView { @State isListReachEnd: boolean = false; @State articleList: Array<Article> = ...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Observed class Article { id: string; title: string; brief: string; isLiked: boolean; likesCount: number; constructor(id: string, title: string, brief: string, isLiked: boolean, likesCount: number) { this.id = id; this.title = title; this.brief = brief; this.isLiked = isLiked; this.like...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct ForEachSort { @State arr: Array<string> = []; build() { Row() { List() { ForEach(this.arr, (item: string) => { ListItem() { Text(item.toString()) .fontSize(16) .textAlign(TextAlign.Center) .size({height: 100,...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct Parent { @State simpleList: Array<string> = ['one', 'two', 'three']; build() { Column() { Button() { Text('Insert Item After First Item').fontSize(30) } .onClick(() => { this.simpleList.splice(1, 0, 'new item'); }) ForEach(this.simpleList,...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Entry @Component struct Parent { @State simpleList: Array<string> = ['one', 'two', 'three']; build() { Column() { Button() { Text('Insert Item After First Item').fontSize(30) } .onClick(() => { this.simpleList.splice(1, 0, 'new item'); console.info(`[onClick]: simpleL...
application-dev\ui\state-management\arkts-rendering-control-foreach.md
ForEach(this.simpleList, (item: string) => { ChildItem({ item: item }) }, (item: string) => item) // Ensure that the key is unique.
application-dev\ui\state-management\arkts-rendering-control-foreach.md
@Observed class Article { id: string; title: string; brief: string; isLiked: boolean; likesCount: number; constructor(id: string, title: string, brief: string, isLiked: boolean, likesCount: number) { this.id = id; this.title = title; this.brief = brief; this.isLiked = isLiked; this.like...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
@Entry @Component struct MyComponent { @State count: number = 0; build() { Column() { Text(`count=${this.count}`) if (this.count > 0) { Text(`count is positive`) .fontColor(Color.Green) } Button('increase count') .onClick(() => { this.count++; ...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
@Component struct CounterView { @State counter: number = 0; label: string = 'unknown'; build() { Column({ space: 20 }) { Text(`${this.label}`) Button(`counter ${this.counter} +1`) .onClick(() => { this.counter += 1; }) } .margin(10) .padding(10) .border({...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
@Component struct CounterView { @Link counter: number; label: string = 'unknown'; build() { Column({ space: 20 }) { Text(`${this.label}`) .fontSize(20) Button(`counter ${this.counter} +1`) .onClick(() => { this.counter += 1; }) } .margin(10) .padding(...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
@Entry @Component struct MyComponent { @State toggle: boolean = false; @State toggleColor: boolean = false; build() { Column({ space: 20 }) { Text('Before') .fontSize(15) if (this.toggle) { Text('Top True, positive 1 top') .backgroundColor('#aaffaa').fontSize(20) ...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
class MyData { str: string; constructor(str: string) { this.str = str; } } @Entry @Component struct Index { @State data1: MyData|undefined = new MyData("branch 0"); @State data2: MyData|undefined = new MyData("branch 1"); build() { Column() { if (this.data1) { // If a Text is added or...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
class MyData { str: string; constructor(str: string) { this.str = str; } } @Entry @Component struct Index { @State data1: MyData|undefined = new MyData("branch 0"); @State data2: MyData|undefined = new MyData("branch 1"); build() { Column() { if (this.data1) { // If a Text is added or...
application-dev\ui\state-management\arkts-rendering-control-ifelse.md
class MyData { str: string; constructor(str: string) { this.str = str; } } @Entry @Component struct Index { @State data1: MyData|undefined = new MyData("branch 0"); @State data2: MyData|undefined = new MyData("branch 1"); build() { Column() { if (this.data1) { // Display the specified...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
/** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/ class MyDataSource extends BasicDataSource { private dataArray: string[] = []; public totalCount(): number { return this.dataArray.length; } public getData(index: number): string { re...
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md
// Array before modification. ["Hello a","Hello b","Hello c","Hello d","Hello e","Hello f","Hello g","Hello h","Hello i","Hello j","Hello k","Hello l","Hello m","Hello n","Hello o","Hello p","Hello q","Hello r"] //Array after modification. ["Hello a","Hello c","Hello d","Hello b","Hello g","Hello f","Hello e","Hello h"...