返回介绍

Picker

发布于 2020-10-20 06:58:13 字数 5372 浏览 928 评论 0 收藏 0

Extends Widget

A widget with a drop-down list of items to choose from.

Import this type with “const {Picker} = require('tabris');

AndroidiOS
Picker on AndroidPicker on iOS

Properties

borderColor

Type: Color

The color of the border of the Picker. On iOS this is a rectangular border around the Picker, on Android it is a single line below the Picker.

fillColor

iOS

Type: Color

The color of the background of the Picker - applies only to iOS.

itemCount

Type: number

The number of items to display.

itemText

Type: (index: number) => string

A function that returns the string to display for a given index.

selectionIndex

Type: number

The index of the currently selected item.

textColor

Type: Color

The color of the text.

Events

borderColorChanged

Fired when the borderColor property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: Color The new value of borderColor.

fillColorChanged

Fired when the fillColor property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: Color The new value of fillColor.

itemCountChanged

Fired when the itemCount property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: number The new value of itemCount.

itemTextChanged

Fired when the itemText property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: (index: number) => string The new value of itemText.

select

Fired when an item was selected by the user.

Event Parameters

  • target: this The widget the event was fired on.

  • index: number Contains the index of the selected item.

selectionIndexChanged

Fired when the selectionIndex property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: number The new value of selectionIndex.

textColorChanged

Fired when the textColor property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: Color The new value of textColor.

Example

const {Picker, ui} = require('tabris');

// Create a picker widget to select a string from a list

const AIRPORTS = [
  {
    id: 'SFO',
    name: 'San Francisco'
  },
  {
    id: 'TXL',
    name: 'Berlin Tegel'
  },
  {
    id: 'FRA',
    name: 'Frankfurt'
  }
];

let picker = new Picker({
  left: 20, top: 20, right: 20,
  itemCount: AIRPORTS.length,
  itemText: (index) => AIRPORTS[index].name,
  selectionIndex: 1
}).appendTo(ui.contentView);

picker.on('select', ({index}) => console.log('Selected ' + AIRPORTS[index].id));

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文