PickerView选择器

PickerView 的功能类似于 Picker ,但它是直接渲染在区域中,而不是弹出窗口。

代码演示

选择器

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'demo-picker-view-basic',
  4. template: `
  5. <div>{{ getValue(value) }}</div>
  6. <PickerView [data]="seasons" [cascade]="false" [(ngModel)]="value" (ngModelChange)="onChange($event)"></PickerView>
  7. `
  8. })
  9. export class DemoPickerViewBasicComponent {
  10. seasons = [
  11. {
  12. label: '2013',
  13. children: [
  14. {
  15. label: '春',
  16. children: []
  17. },
  18. {
  19. label: '夏',
  20. children: []
  21. }
  22. ]
  23. },
  24. {
  25. label: '2014',
  26. children: [
  27. {
  28. label: '春'
  29. },
  30. {
  31. label: '夏'
  32. }
  33. ]
  34. }
  35. ];
  36. value = ['2014', '夏'];
  37. onChange(result) {
  38. console.log(this.value, result);
  39. }
  40. getValue(result) {
  41. let value = [];
  42. let temp = '';
  43. result.forEach(item => {
  44. value.push(item.label || item);
  45. temp += item.label || item;
  46. });
  47. return value;
  48. }
  49. }

PickerView选择器 - 图1

API

参数说明类型默认值
[data]数据源Array<{value, label}> | Array<Array<{value, label}>-
[cascade]是否级联booleantrue
[cols]列数number3
[itemStyle]每列样式object-
[indicatorStyle]indicator 样式object-
[(ngModel)]当前值, 格式是[value1, value2, value3], 对应数据源的相应级层 valueArray-
(ngModelChange)选中后的回调EventEmitter<any[]>-