diff --git a/en/application-dev/quick-start/arkts-rendering-control.md b/en/application-dev/quick-start/arkts-rendering-control.md index dff2cda50c02afabc15d0f5c8bb576218cab316e..d0ff5a8c183d8efba03b12f7343f001a3ba31fe5 100644 --- a/en/application-dev/quick-start/arkts-rendering-control.md +++ b/en/application-dev/quick-start/arkts-rendering-control.md @@ -34,7 +34,7 @@ Column() { You can use **ForEach** to obtain data from arrays and create components for each data item. -``` +```ts ForEach( arr: any[], itemGenerator: (item: any, index?: number) => void, @@ -275,7 +275,7 @@ struct MyComponent { > > ```ts > LazyForEach(dataSource, -> item => Text(`${item.i}. item.data.label`)), +> item => Text(`${item.i}. item.data.label`), > item => item.data.id.toString()) > ``` diff --git a/en/application-dev/reference/arkui-js/Readme-EN.md b/en/application-dev/reference/arkui-js/Readme-EN.md index d14e06d8a3a83329a2a6e2b508508e03c93aea4c..c46abd3bd91d1acbf99bb15152d3f55f636483eb 100644 --- a/en/application-dev/reference/arkui-js/Readme-EN.md +++ b/en/application-dev/reference/arkui-js/Readme-EN.md @@ -96,10 +96,9 @@ - Custom Components - [Basic Usage](js-components-custom-basic-usage.md) - - [Style Inheritance](js-components-custom-style.md) - - [Custom Events](js-components-custom-events.md) - [props](js-components-custom-props.md) - - [Event Parameter](js-components-custom-event-parameter.md) + - [Style Inheritance](js-components-custom-style.md) - [slot](js-components-custom-slot.md) - [Lifecycle Definition](js-components-custom-lifecycle.md) -- [Data Type Attributes](js-appendix-types.md) +- [Dynamic Component Creation](js-components-create-elements.md) +- [Data Type Attributes](js-appendix-types.md) diff --git a/en/application-dev/reference/arkui-js/figures/animate-4.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001127125126.gif similarity index 100% rename from en/application-dev/reference/arkui-js/figures/animate-4.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001127125126.gif diff --git a/en/application-dev/reference/arkui-js/en-us_image_0000001127284938.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001127284938.gif similarity index 100% rename from en/application-dev/reference/arkui-js/en-us_image_0000001127284938.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001127284938.gif diff --git a/en/application-dev/reference/arkui-js/en-us_image_0000001167662852.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001167662852.gif similarity index 100% rename from en/application-dev/reference/arkui-js/en-us_image_0000001167662852.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001167662852.gif diff --git a/en/application-dev/reference/arkui-js/en-us_image_0000001173324703.gif b/en/application-dev/reference/arkui-js/figures/en-us_image_0000001173324703.gif similarity index 100% rename from en/application-dev/reference/arkui-js/en-us_image_0000001173324703.gif rename to en/application-dev/reference/arkui-js/figures/en-us_image_0000001173324703.gif diff --git a/en/application-dev/reference/arkui-js/js-components-create-elements.md b/en/application-dev/reference/arkui-js/js-components-create-elements.md new file mode 100644 index 0000000000000000000000000000000000000000..b0afebfa68e40737f66361e501c67536472df8ac --- /dev/null +++ b/en/application-dev/reference/arkui-js/js-components-create-elements.md @@ -0,0 +1,145 @@ +# Dynamic Component Creation + +You can dynamically add components with specified attributes and styles to pages. + +> **NOTE** +> +> This API is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. + + +## createElement + +createElement(tag: string): Element + +Creates a component object. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------------ | ---- | ------- | +| tag | string | Yes | Component name.| + +**Return value** + +| Type | Description | +| ----------- | ------------- | +| Element | Component object corresponding to the value of **tag**.| + +```js +let newImage = dom.createElement('image') +``` + + +## setAttribute + +setAttribute(name: string, value: string): void + +Dynamically sets the attributes of this component. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------------ | ---- | ------- | +| name | string | Yes | Attribute name.| +| value | string | Yes | Attribute value.| + +```js +newImage.setAttribute('src', 'common/testImage.jpg') +``` + + +## setStyle + +setStyle(name: string, value: string): boolean + +Dynamically sets the style of this component. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------------ | ---- | ------- | +| name | string | Yes | Style name.| +| value | string | Yes | Style value.| + +**Return value** + +| Type | Description | +| ----------- | ------------- | +| boolean | Returns **true** if the setting is successful; returns **false** otherwise.| + +```js +newImage.setStyle('width', '120px') +``` + + +## addChild + +addChild(child: Element): void + +Adds a dynamically created component to the parent component. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------------ | ---- | ------- | +| child | Element | Yes | Component object.| + +```js +newDiv.addChild(newImage) +``` + + +## Example + +```html + +