Picker

Extends Widget

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

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

Android iOS
Picker on Android Picker 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

  1. const {Picker, ui} = require('tabris');
  2. // Create a picker widget to select a string from a list
  3. const AIRPORTS = [
  4. {
  5. id: 'SFO',
  6. name: 'San Francisco'
  7. },
  8. {
  9. id: 'TXL',
  10. name: 'Berlin Tegel'
  11. },
  12. {
  13. id: 'FRA',
  14. name: 'Frankfurt'
  15. }
  16. ];
  17. let picker = new Picker({
  18. left: 20, top: 20, right: 20,
  19. itemCount: AIRPORTS.length,
  20. itemText: (index) => AIRPORTS[index].name,
  21. selectionIndex: 1
  22. }).appendTo(ui.contentView);
  23. picker.on('select', ({index}) => console.log('Selected ' + AIRPORTS[index].id));

See also

原文:

https://youjingyu.github.io/Tabris-Documention/?folderName=widgets&pageName=Picker.html