Cascader 级联多选

全选,value= [[‘bamboo’], [‘light’]]
image.png

部分选择,ShowCheckedStrategy 选择回填方式
image.png

  1. import { Cascader } from 'antd';
  2. const { SHOW_CHILD } = Cascader;
  3. function App() {
  4. // 字符串二维数组
  5. function onChange(value: string[][]) {
  6. const values = [
  7. ['bamboo'],
  8. ['light', 0],
  9. ['light', 1],
  10. ['light', 2]
  11. ]
  12. }
  13. return (
  14. <Cascader
  15. options={options}
  16. onChange={onChange}
  17. multiple
  18. maxTagCount="responsive"
  19. showCheckedStrategy={SHOW_CHILD}
  20. defaultValue={['bamboo']}
  21. />
  22. )
  23. }

ANT_CASCADER_NOT_FOUND

Cascader组件options为空数组时,暂无数据作为了下拉选项,点击后赋值到了组件内;ANT_CASCADER_NOT_FOUND
https://github.com/ant-design/ant-design/commit/85d81e7e3ed4913dff89ce1b776839bb52e31132

  1. return [{ label: notFoundContent, value: 'ANT_CASCADER_NOT_FOUND', disabled: true }];

changeOnSelect

点选每级菜单选项值都会发生变化
Cascader 把 selectedOptions添加为最终输出值

  1. function App() {
  2. function onChange(values, selectedOptions) {
  3. const labels = selectedOptions.map(it => it.label);
  4. form.setFieldsValue({ username: labels });
  5. }
  6. return (
  7. <Cascader
  8. options={regionOptions}
  9. onChange={onChange}
  10. changeOnSelect
  11. />
  12. )
  13. }