未验证 提交 939bef77 编写于 作者: L luoying_ace 提交者: Gitee

update zh-cn/application-dev/reference/arkui-ts/ts-methods-textpicker-dialog.md.

Signed-off-by: Nluoying_ace <luoying19@huawei.com>
上级 9db4d91b
...@@ -3,13 +3,10 @@ ...@@ -3,13 +3,10 @@
根据指定的选择范围创建文本选择器,展示在弹窗上。 根据指定的选择范围创建文本选择器,展示在弹窗上。
> **说明:** > **说明:**
>
> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## TextPickerDialog.show ## TextPickerDialog.show
show(options?: TextPickerDialogOptions) show(options?: TextPickerDialogOptions)
...@@ -17,21 +14,23 @@ show(options?: TextPickerDialogOptions) ...@@ -17,21 +14,23 @@ show(options?: TextPickerDialogOptions)
定义文本滑动选择器弹窗并弹出。 定义文本滑动选择器弹窗并弹出。
- TextPickerDialogOptions参数说明 - TextPickerDialogOptions参数说明
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| range | string[]&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md#resource类型) | 是 | - | 选择器的数据选择范围。 | | range | string[]&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md#resource类型) | 是 | - | 设置文本选择器的选择范围。 |
| selected | number | 否 | 0 | 选中项在数组中的index值。 | | selected | number | 否 | 0 | 设置选中项的索引值。 |
| value | string | 否 | - | 选中项文本值。当设置了selected参数时,该值不生效。如果该值不在range范围内,则默认取range第一个元素。| | value | string | 否 | - | 设置选中项的文本内容。当设置了selected参数时,该参数不生效。如果设置的value值不在range范围内,则默认取range第一个元素。|
| defaultPickerItemHeight | number \| string | 否 | - | 默认Picker内容项元素高度。 | | defaultPickerItemHeight | number \| string | 否 | - | 设置选择器中选项的高度。 |
| onAccept | (value: TextPickerResult) => void | 否 | - | 点击弹窗中确定按钮时触发。 | | onAccept | (value: TextPickerResult) => void | 否 | - | 点击弹窗中的“确定”按钮时触发该回调。 |
| onCancel | () => void | 否 | - | 点击弹窗中取消按钮时触发。 | | onCancel | () => void | 否 | - | 点击弹窗中的“取消”按钮时触发该回调。 |
| onChange | (value: TextPickerResult) => void | 否 | - | 滑动选择器,当前选择项改变时触发。 | | onChange | (value: TextPickerResult) => void | 否 | - | 滑动弹窗中的选择器使当前选中项改变时触发该回调。 |
- TextPickerResult对象说明 - TextPickerResult对象说明
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| value | string | 选中项文本。 | | value | string | 选中项的文本内容。 |
| index | number | 选中项在数组中的index值。 | | index | number | 选中项在选择范围数组中的索引值。 |
## 示例 ## 示例
...@@ -40,29 +39,31 @@ show(options?: TextPickerDialogOptions) ...@@ -40,29 +39,31 @@ show(options?: TextPickerDialogOptions)
@Entry @Entry
@Component @Component
struct TextPickerDialogExample { struct TextPickerDialogExample {
@State select: number = 1 @State select: number = 2
private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4'] private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4', 'banana5']
build() { build() {
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, Column() {
justifyContent: FlexAlign.Center }) { Button("TextPickerDialog")
Button("TextPickerDialog").onClick(() => { .margin(20)
TextPickerDialog.show({ .onClick(() => {
range: this.fruits, TextPickerDialog.show({
selected: this.select, range: this.fruits,
onAccept: (value: TextPickerResult) => { selected: this.select,
console.info("TextPickerDialog:onAccept()" + JSON.stringify(value)) onAccept: (value: TextPickerResult) => {
this.select = value.index // 设置select为按下确定按钮时候的选中项index,这样当弹窗再次弹出时显示选中的是上一次确定的选项
}, this.select = value.index
onCancel: () => { console.info("TextPickerDialog:onAccept()" + JSON.stringify(value))
console.info("TextPickerDialog:onCancel()") },
}, onCancel: () => {
onChange: (value: TextPickerResult) => { console.info("TextPickerDialog:onCancel()")
console.info("TextPickerDialog:onChange()" + JSON.stringify(value)) },
} onChange: (value: TextPickerResult) => {
console.info("TextPickerDialog:onChange()" + JSON.stringify(value))
}
})
}) })
}) }.width('100%')
}
} }
} }
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册