當(dāng)一個數(shù)據(jù)集合有清晰的層級結(jié)構(gòu)時,可通過級聯(lián)選擇器逐級查看并選擇。
有兩種觸發(fā)子菜單的方式
只需為 Cascader 的options
屬性指定選項數(shù)組即可渲染出一個級聯(lián)選擇器。通過expandTrigger
可以定義展開子級菜單的觸發(fā)方式。本例還展示了onChange
事件,它的參數(shù)為 Cascader 的綁定值:一個由各級菜單的值所組成的數(shù)組。
constructor(props) {
super(props);
this.state = {
options: [{
value: 'zhinan',
label: '指南',
children: [{
value: 'shejiyuanze',
label: '設(shè)計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}],
selectedOptions: [],
selectedOptions2: []
}
}
handleChange(key, value) {
this.setState({ [key]: value });
console.log(value);
}
render() {
return (
<div>
<div className="block">
<span className="demonstration">默認(rèn) click 觸發(fā)子菜單</span>
<Cascader
options={this.state.options}
value={this.state.selectedOptions}
onChange={this.handleChange.bind(this, 'selectedOptions')} />
</div>
<div className="block">
<span className="demonstration">hover 觸發(fā)子菜單</span>
<Cascader
options={this.state.options}
expandTrigger="hover"
value={this.state.selectedOptions2}
onChange={this.handleChange.bind(this, 'selectedOptions2')} />
</div>
</div>
)
}
通過在數(shù)據(jù)源中設(shè)置 disabled
字段來聲明該選項是禁用的
本例中,options
指定的數(shù)組中的第一個元素含有disabled: true
鍵值對,因此是禁用的。在默認(rèn)情況下,Cascader 會檢查數(shù)據(jù)中每一項的disabled
字段是否為true
,如果你的數(shù)據(jù)中表示禁用含義的字段名不為disabled
,可以通過props
屬性來指定(詳見下方 API 表格)。當(dāng)然,value
、label
和children
這三個字段名也可以通過同樣的方式指定。
constructor(props) {
super(props);
this.state = {
optionsWithDisabled: [{
value: 'zhinan',
label: '指南',
disabled: true,
children: [{
value: 'shejiyuanze',
label: '設(shè)計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}]
};
}
render() {
return (
<Cascader
options={this.state.optionsWithDisabled}
/>
)
}
可以僅在輸入框中顯示選中項最后一級的標(biāo)簽,而不是選中項所在的完整路徑。
屬性show-all-levels
定義了是否顯示完整的路徑,將其賦值為false
則僅顯示最后一級
constructor(props) {
super(props);
this.state = {
options: [{
value: 'zhinan',
label: '指南',
children: [{
value: 'shejiyuanze',
label: '設(shè)計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}]
}
}
render() {
return (
<Cascader
options={this.state.options}
showAllLevels={false}
/>
)
}
默認(rèn)值通過數(shù)組的方式指定。
constructor(props) {
super(props);
this.state = {
options: [{
value: 'zhinan',
label: '指南',
children: [{
value: 'shejiyuanze',
label: '設(shè)計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}],
selectedOptions3: ['zujian', 'data', 'tag']
}
}
render() {
return (
<Cascader
options={this.state.options}
value={this.state.selectedOptions3}
/>
)
}
點擊或移入選項即表示選中該項,可用于選擇任意一級菜單的選項。
若需要允許用戶選擇任意一級選項,則可將change-on-select
賦值為true
constructor(props) {
super(props);
this.state = {
options: [{
value: 'zhinan',
label: '指南',
children: [{
value: 'shejiyuanze',
label: '設(shè)計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}]
};
}
render() {
return (
<Cascader
options={this.state.options}
changeOnSelect={true}
/>
)
}
當(dāng)選中某一級時,動態(tài)加載該級下的選項。
本例的選項數(shù)據(jù)源在初始化時不包含城市數(shù)據(jù)。利用active-item-change
事件,可以在用戶點擊某個省份時拉取該省份下的城市數(shù)據(jù)。此外,本例還展示了props
屬性的用法。
constructor(props) {
super(props);
this.state = {
options2: [{
label: '江蘇',
cities: []
}, {
label: '浙江',
cities: []
}],
props: {
value: 'label',
children: 'cities'
}
};
}
handleItemChange(val) {
console.log('active item:', val);
setTimeout(() => {
if (val.indexOf('江蘇') > -1 && !this.state.options2[0].cities.length) {
this.state.options2[0].cities = [{
label: '南京'
}];
} else if (val.indexOf('浙江') > -1 && !this.state.options2[1].cities.length) {
this.state.options2[1].cities = [{
label: '杭州'
}];
}
this.forceUpdate();
}, 300);
}
render() {
return (
<Cascader
props={this.state.props}
options={this.state.options2}
activeItemChange={this.handleItemChange.bind(this)}
/>
)
}
可以快捷地搜索選項并選擇。
將filterable
賦值為true
即可打開搜索功能。
constructor(props) {
super(props);
this.state = {
options: [{
value: 'zhinan',
label: '指南',
children: [{
value: 'shejiyuanze',
label: '設(shè)計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導(dǎo)航',
children: [{
value: 'cexiangdaohang',
label: '側(cè)向?qū)Ш?
}, {
value: 'dingbudaohang',
label: '頂部導(dǎo)航'
}]
}]
}, {
value: 'zujian',
label: '組件',
children: [{
value: 'basic',
label: 'Basic',
children: [{
value: 'layout',
label: 'Layout 布局'
}, {
value: 'color',
label: 'Color 色彩'
}, {
value: 'typography',
label: 'Typography 字體'
}, {
value: 'icon',
label: 'Icon 圖標(biāo)'
}, {
value: 'button',
label: 'Button 按鈕'
}]
}, {
value: 'form',
label: 'Form',
children: [{
value: 'radio',
label: 'Radio 單選框'
}, {
value: 'checkbox',
label: 'Checkbox 多選框'
}, {
value: 'input',
label: 'Input 輸入框'
}, {
value: 'input-number',
label: 'InputNumber 計數(shù)器'
}, {
value: 'select',
label: 'Select 選擇器'
}, {
value: 'cascader',
label: 'Cascader 級聯(lián)選擇器'
}, {
value: 'switch',
label: 'Switch 開關(guān)'
}, {
value: 'slider',
label: 'Slider 滑塊'
}, {
value: 'time-picker',
label: 'TimePicker 時間選擇器'
}, {
value: 'date-picker',
label: 'DatePicker 日期選擇器'
}, {
value: 'datetime-picker',
label: 'DateTimePicker 日期時間選擇器'
}, {
value: 'upload',
label: 'Upload 上傳'
}, {
value: 'rate',
label: 'Rate 評分'
}, {
value: 'form',
label: 'Form 表單'
}]
}, {
value: 'data',
label: 'Data',
children: [{
value: 'table',
label: 'Table 表格'
}, {
value: 'tag',
label: 'Tag 標(biāo)簽'
}, {
value: 'progress',
label: 'Progress 進度條'
}, {
value: 'tree',
label: 'Tree 樹形控件'
}, {
value: 'pagination',
label: 'Pagination 分頁'
}, {
value: 'badge',
label: 'Badge 標(biāo)記'
}]
}, {
value: 'notice',
label: 'Notice',
children: [{
value: 'alert',
label: 'Alert 警告'
}, {
value: 'loading',
label: 'Loading 加載'
}, {
value: 'message',
label: 'Message 消息提示'
}, {
value: 'message-box',
label: 'MessageBox 彈框'
}, {
value: 'notification',
label: 'Notification 通知'
}]
}, {
value: 'navigation',
label: 'Navigation',
children: [{
value: 'menu',
label: 'NavMenu 導(dǎo)航菜單'
}, {
value: 'tabs',
label: 'Tabs 標(biāo)簽頁'
}, {
value: 'breadcrumb',
label: 'Breadcrumb 面包屑'
}, {
value: 'dropdown',
label: 'Dropdown 下拉菜單'
}, {
value: 'steps',
label: 'Steps 步驟條'
}]
}, {
value: 'others',
label: 'Others',
children: [{
value: 'dialog',
label: 'Dialog 對話框'
}, {
value: 'tooltip',
label: 'Tooltip 文字提示'
}, {
value: 'popover',
label: 'Popover 彈出框'
}, {
value: 'card',
label: 'Card 卡片'
}, {
value: 'carousel',
label: 'Carousel 走馬燈'
}, {
value: 'collapse',
label: 'Collapse 折疊面板'
}]
}]
}, {
value: 'ziyuan',
label: '資源',
children: [{
value: 'axure',
label: 'Axure Components'
}, {
value: 'sketch',
label: 'Sketch Templates'
}, {
value: 'jiaohu',
label: '組件交互文檔'
}]
}]
}
}
render() {
return (
<div>
<div className="block">
<span className="demonstration">只可選擇最后一級菜單的選項</span>
<Cascader
placeholder="試試搜索:指南"
options={this.state.options}
filterable={true}
/>
</div>
<div className="block">
<span className="demonstration">可選擇任意一級菜單的選項</span>
<Cascader
placeholder="試試搜索:指南"
options={this.state.options}
filterable={true}
changeOnSelect={true}
/>
</div>
</div>
)
}
隱藏代碼
參數(shù) | 說明 | 類型 | 可選值 | 默認(rèn)值 |
---|---|---|---|---|
options | 可選項數(shù)據(jù)源,鍵名可通過 props 屬性配置 |
array | — | — |
props | 配置選項,具體見下表 | object | — | — |
value | 選中項綁定值 | array | — | — |
popperClass | 自定義浮層類名 | string | — | — |
placeholder | 輸入框占位文本 | string | — | 請選擇 |
disabled | 是否禁用 | boolean | — | false |
clearable | 是否支持清空選項 | boolean | — | false |
expandTrigger | 次級菜單的展開方式 | string | click / hover | click |
showAllLevels | 輸入框中是否顯示選中值的完整路徑 | boolean | — | true |
filterable | 是否可搜索選項 | boolean | — | — |
debounce | 搜索關(guān)鍵詞輸入的去抖延遲,毫秒 | number | — | 300 |
changeOnSelect | 是否允許選擇任意一級的選項 | boolean | — | false |
size | 尺寸 | string | large / small / mini | — |
beforeFilter | 可選參數(shù), 篩選之前的鉤子,參數(shù)為輸入的值,若返回 false 或者返回 Promise 且被 reject,則停止篩選。 | function(value) | — | — |
參數(shù) | 說明 | 類型 | 可選值 | 默認(rèn)值 |
---|---|---|---|---|
value | 指定選項的值為選項對象的某個屬性值 | string | — | — |
label | 指定選項標(biāo)簽為選項對象的某個屬性值 | string | — | — |
children | 指定選項的子選項為選項對象的某個屬性值 | string | — | — |
disabled | 指定選項的禁用為選項對象的某個屬性值 | string | — | — |
事件名稱 | 說明 | 回調(diào)參數(shù) |
---|---|---|
change | 當(dāng)綁定值變化時觸發(fā)的事件 | 當(dāng)前值 |
activeItemChange | 當(dāng)父級選項變化時觸發(fā)的事件,僅在 change-on-select 為 false 時可用 |
各父級選項組成的數(shù)組 |
更多建議: