Skip to main content

ion-picker-legacy

scoped
弃用通知

ion-picker-legacy 已弃用,并将在下一个主要版本中删除。尽快迁移到 ion-picker

¥ion-picker-legacy is deprecated and will be removed in the next major release. Migrate to ion-picker as soon as possible.

选择器是一个对话框,下面显示一行按钮和列。它出现在应用内容的顶部和视口的底部。

¥A Picker is a dialog that displays a row of buttons and columns underneath. It appears on top of the app's content, and at the bottom of the viewport.

¥Inline Pickers (Recommended)

可以通过直接在模板中编写组件来使用 ion-picker-legacy。这减少了为了显示选取器而需要连接的处理程序的数量。

¥ion-picker-legacy can be used by writing the component directly in your template. This reduces the number of handlers you need to wire up in order to present the Picker.

Console
Console messages will appear here when logged from the example above.

使用 isOpen

¥Using isOpen

ion-picker-legacy 上的 isOpen 属性允许开发者从其应用状态控制选取器的渲染状态。这意味着当 isOpen 设置为 true 时,将显示选取器,而当 isOpen 设置为 false 时,将关闭选取器。

¥The isOpen property on ion-picker-legacy allows developers to control the presentation state of the Picker from their application state. This means when isOpen is set to true the Picker will be presented, and when isOpen is set to false the Picker will be dismissed.

isOpen 使用单向数据绑定,这意味着当选取器关闭时,它不会自动设置为 false。开发者应该监听 ionPickerDidDismissdidDismiss 事件并将 isOpen 设置为 false。这样做的原因是它阻止了 ion-picker 的内部与应用的状态紧密耦合。通过单向数据绑定,选择器只需要关心反应变量提供的布尔值。对于双向数据绑定,选择器需要关注布尔值以及反应变量本身的存在。这可能会导致不确定的行为并使应用更难以调试。

¥isOpen uses a one-way data binding, meaning it will not automatically be set to false when the Picker is dismissed. Developers should listen for the ionPickerDidDismiss or didDismiss event and set isOpen to false. The reason for this is it prevents the internals of ion-picker from being tightly coupled with the state of the application. With a one way data binding, the Picker only needs to concern itself with the boolean value that the reactive variable provides. With a two way data binding, the Picker needs to concern itself with both the boolean value as well as the existence of the reactive variable itself. This can lead to non-deterministic behaviors and make applications harder to debug.

Console
Console messages will appear here when logged from the example above.

控制器选择器

¥Controller Pickers

pickerController 可用于需要对选择器何时显示和消失进行更多控制的情况。

¥The pickerController can be used in situations where more control is needed over when the Picker is presented and dismissed.

Console
Console messages will appear here when logged from the example above.

多列

¥Multiple Columns

columns 属性可用于显示具有多列不同选项的选取器。

¥The columns property can be used to display a Picker with multiple columns of different options.

Console
Console messages will appear here when logged from the example above.

接口

¥Interfaces

PickerButton

interface PickerButton {
text?: string;
role?: string;
cssClass?: string | string[];
handler?: (value: any) => boolean | void;
}

PickerColumn

interface PickerColumn {
name: string;
align?: string;
/**

* Changing this value allows the initial value of a picker column to be set.
*/
selectedIndex?: number;
prevSelected?: number;
prefix?: string;
suffix?: string;
options: PickerColumnOption[];
cssClass?: string | string[];
columnWidth?: string;
prefixWidth?: string;
suffixWidth?: string;
optionsWidth?: string;
}

PickerColumnOption

interface PickerColumnOption {
text?: string;
value?: any;
disabled?: boolean;
duration?: number;
transform?: string;
selected?: boolean;
/**

* The optional text to assign as the aria-label on the picker column option.
*/
ariaLabel?: string;
}

PickerOptions

interface PickerOptions {
columns: PickerColumn[];
buttons?: PickerButton[];
cssClass?: string | string[];
showBackdrop?: boolean;
backdropDismiss?: boolean;
animated?: boolean;

mode?: Mode;
keyboardClose?: boolean;
id?: string;
htmlAttributes?: { [key: string]: any };

enterAnimation?: AnimationBuilder;
leaveAnimation?: AnimationBuilder;
}

属性

¥Properties

animated

DescriptionIf true, the picker will animate.
Attributeanimated
Typeboolean
Defaulttrue

backdropDismiss

DescriptionIf true, the picker will be dismissed when the backdrop is clicked.
Attributebackdrop-dismiss
Typeboolean
Defaulttrue

buttons

DescriptionArray of buttons to be displayed at the top of the picker.
Attributeundefined
TypePickerButton[]
Default[]

columns

DescriptionArray of columns to be displayed in the picker.
Attributeundefined
TypePickerColumn[]
Default[]

cssClass

DescriptionAdditional classes to apply for custom CSS. If multiple classes are provided they should be separated by spaces.
Attributecss-class
Typestring | string[] | undefined
Defaultundefined

duration

DescriptionNumber of milliseconds to wait before dismissing the picker.
Attributeduration
Typenumber
Default0

enterAnimation

DescriptionAnimation to use when the picker is presented.
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) | undefined
Defaultundefined

htmlAttributes

DescriptionAdditional attributes to pass to the picker.
Attributeundefined
Typeundefined | { [key: string]: any; }
Defaultundefined

isOpen

DescriptionIf true, the picker will open. If false, the picker will close. Use this if you need finer grained control over presentation, otherwise just use the pickerController or the trigger property. Note: isOpen will not automatically be set back to false when the picker dismisses. You will need to do that in your code.
Attributeis-open
Typeboolean
Defaultfalse

keyboardClose

DescriptionIf true, the keyboard will be automatically dismissed when the overlay is presented.
Attributekeyboard-close
Typeboolean
Defaulttrue

leaveAnimation

DescriptionAnimation to use when the picker is dismissed.
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) | undefined
Defaultundefined

mode

DescriptionThe mode determines which platform styles to use.
Attributemode
Type"ios" | "md"
Defaultundefined

showBackdrop

DescriptionIf true, a backdrop will be displayed behind the picker.
Attributeshow-backdrop
Typeboolean
Defaulttrue

trigger

DescriptionAn ID corresponding to the trigger element that causes the picker to open when clicked.
Attributetrigger
Typestring | undefined
Defaultundefined

事件

¥Events

NameDescriptionBubbles
didDismissEmitted after the picker has dismissed. Shorthand for ionPickerDidDismiss.true
didPresentEmitted after the picker has presented. Shorthand for ionPickerWillDismiss.true
ionPickerDidDismissEmitted after the picker has dismissed.true
ionPickerDidPresentEmitted after the picker has presented.true
ionPickerWillDismissEmitted before the picker has dismissed.true
ionPickerWillPresentEmitted before the picker has presented.true
willDismissEmitted before the picker has dismissed. Shorthand for ionPickerWillDismiss.true
willPresentEmitted before the picker has presented. Shorthand for ionPickerWillPresent.true

方法

¥Methods

dismiss

DescriptionDismiss the picker overlay after it has been presented.
Signaturedismiss(data?: any, role?: string) => Promise<boolean>

getColumn

DescriptionGet the column that matches the specified name.
SignaturegetColumn(name: string) => Promise<PickerColumn | undefined>

onDidDismiss

DescriptionReturns a promise that resolves when the picker did dismiss.
SignatureonDidDismiss<T = any>() => Promise<OverlayEventDetail<T>>

onWillDismiss

DescriptionReturns a promise that resolves when the picker will dismiss.
SignatureonWillDismiss<T = any>() => Promise<OverlayEventDetail<T>>

present

DescriptionPresent the picker overlay after it has been created.
Signaturepresent() => Promise<void>

CSS 阴影部分

¥CSS Shadow Parts

No CSS shadow parts available for this component.

CSS 自定义属性

¥CSS Custom Properties

NameDescription
--backdrop-opacityOpacity of the backdrop
--backgroundBackground of the picker
--background-rgbBackground of the picker in rgb format
--border-colorBorder color of the picker
--border-radiusBorder radius of the picker
--border-styleBorder style of the picker
--border-widthBorder width of the picker
--heightHeight of the picker
--max-heightMaximum height of the picker
--max-widthMaximum width of the picker
--min-heightMinimum height of the picker
--min-widthMinimum width of the picker
--widthWidth of the picker

插槽

¥Slots

No slots available for this component.