ant-design/components/cascader/demo/disabled-option.md

71 lines
1.1 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 4
title:
zh-CN: 禁用选项
en-US: Disabled option
2016-03-31 09:40:55 +08:00
---
2016-01-25 15:31:08 +08:00
## zh-CN
2016-01-25 15:31:08 +08:00
通过指定 options 里的 `disabled` 字段。
## en-US
Disable option by specifying the `disabled` property in `options`.
```tsx
2016-01-25 15:31:08 +08:00
import { Cascader } from 'antd';
2022-05-23 14:37:16 +08:00
import React from 'react';
2016-01-25 15:31:08 +08:00
interface Option {
value: string;
label: string;
disabled?: boolean;
children?: Option[];
}
const options: Option[] = [
2019-05-07 14:57:32 +08:00
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [
{
value: 'xihu',
label: 'West Lake',
},
],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
disabled: true,
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
},
],
},
],
},
];
2016-01-25 15:31:08 +08:00
const onChange = (value: string[]) => {
2016-01-25 15:31:08 +08:00
console.log(value);
};
const App: React.FC = () => <Cascader options={options} onChange={onChange} />;
2016-01-25 15:31:08 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```