PickerView 选择器

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

代码演示

选择器

  1. import { PickerView, WhiteSpace } from 'antd-mobile';
  2. const seasons = [
  3. [
  4. {
  5. label: '2013',
  6. value: '2013',
  7. },
  8. {
  9. label: '2014',
  10. value: '2014',
  11. },
  12. ],
  13. [
  14. {
  15. label: '春',
  16. value: '春',
  17. },
  18. {
  19. label: '夏',
  20. value: '夏',
  21. },
  22. ],
  23. ];
  24. const season = [
  25. {
  26. label: '春',
  27. value: '春',
  28. },
  29. {
  30. label: '夏',
  31. value: '夏',
  32. },
  33. ];
  34. const province = [
  35. {
  36. label: '北京',
  37. value: '01',
  38. children: [
  39. {
  40. label: '东城区',
  41. value: '01-1',
  42. },
  43. {
  44. label: '西城区',
  45. value: '01-2',
  46. },
  47. {
  48. label: '崇文区',
  49. value: '01-3',
  50. },
  51. {
  52. label: '宣武区',
  53. value: '01-4',
  54. },
  55. ],
  56. },
  57. {
  58. label: '浙江',
  59. value: '02',
  60. children: [
  61. {
  62. label: '杭州',
  63. value: '02-1',
  64. children: [
  65. {
  66. label: '西湖区',
  67. value: '02-1-1',
  68. },
  69. {
  70. label: '上城区',
  71. value: '02-1-2',
  72. },
  73. {
  74. label: '江干区',
  75. value: '02-1-3',
  76. },
  77. {
  78. label: '下城区',
  79. value: '02-1-4',
  80. },
  81. ],
  82. },
  83. {
  84. label: '宁波',
  85. value: '02-2',
  86. children: [
  87. {
  88. label: 'xx区',
  89. value: '02-2-1',
  90. },
  91. {
  92. label: 'yy区',
  93. value: '02-2-2',
  94. },
  95. ],
  96. },
  97. {
  98. label: '温州',
  99. value: '02-3',
  100. },
  101. {
  102. label: '嘉兴',
  103. value: '02-4',
  104. },
  105. {
  106. label: '湖州',
  107. value: '02-5',
  108. },
  109. {
  110. label: '绍兴',
  111. value: '02-6',
  112. },
  113. ],
  114. },
  115. ];
  116. class PickerViewExample extends React.Component {
  117. state = {
  118. value: null,
  119. };
  120. onChange = (value) => {
  121. console.log(value);
  122. this.setState({
  123. value,
  124. });
  125. }
  126. onScrollChange = (value) => {
  127. console.log(value);
  128. }
  129. render() {
  130. return (
  131. <div>
  132. <PickerView
  133. onChange={this.onChange}
  134. onScrollChange={this.onScrollChange}
  135. value={this.state.value}
  136. data={seasons}
  137. cascade={false}
  138. />
  139. <WhiteSpace /><WhiteSpace />
  140. <PickerView
  141. data={season}
  142. cascade={false}
  143. />
  144. <WhiteSpace /><WhiteSpace />
  145. <PickerView
  146. data={province}
  147. value={['02', '02-1', '02-1-1']}
  148. />
  149. </div>
  150. );
  151. }
  152. }
  153. ReactDOM.render(<PickerViewExample />, mountNode);

PickerView选择器 - 图1

API

属性说明类型默认值
data数据源Array<{value, label}> / Array<Array<{value, label}>>-
value值, 格式是[value1, value2, value3], 对应数据源的相应级层 valueArray-
cascade是否级联Booleantrue
cols列数Number3
onChange选中后的回调,可使用rc-form(val): void-
prefixClsprefix classstringam-picker
pickerPrefixClspicker prefix classstringam-picker-col
itemStyle每列样式Object-
indicatorStyleindicator 样式Object-