UI视图
Picker
从一组选项中选择一个值。
受控选择器。每个选项都是一个用 tag 标记取值的视图,selection 必须恰好命中其中一个选项的 tag。
import { Modifier, Picker, Text, useState } from "onescript/views"
function ColorPicker() {
const [color, setColor] = useState("red")
return (
<Picker
label="颜色"
selection={color}
onSelectionChange={setColor}
>
<Text modifier={Modifier.tag("red")}>红色</Text>
<Text modifier={Modifier.tag("blue")}>蓝色</Text>
</Picker>
)
}| Prop | Type | 说明 |
|---|---|---|
selection | string | number | 选中选项的 tag。 |
onSelectionChange | (value) => void | 用户选择后执行,参数为对应选项的 tag。 |
label | ViewChild | 可选标签。 |
children | ViewChild | 选项,可以来自数组、Fragment 或组件。 |
tag 不能重复,且 selection 必须命中其中一个,否则渲染会报错。1 与 "1" 是不同的 tag。
使用 pickerStyle 切换菜单、分段、滚轮等样式。也支持修饰符。仅在 App 和 Action 视图会话中可用;在 Widget 中使用会报「不支持的视图类型」错误。
How is this guide?
最后更新于