Skip to content

添加noData参数,设置异步获取到的子节点为空时的提示文案 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
padding: 0;
border-right: 1px solid #e9e9e9;
overflow: auto;
&-not-fount {
position: relative;
text-align: center;
top: 50%;
transform: translateY(-50%);
color: #d9d9d9;
}
&:last-child {
border-right: 0;
}
Expand Down Expand Up @@ -163,4 +170,4 @@
transform-origin: 0% 100%;
transform: scaleY(0.8);
}
}
}
24 changes: 17 additions & 7 deletions examples/dynamic-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const addressOptions = [{
label: '浙江',
isLeaf: false,
value: 'zj',
}, {
label: '北京',
isLeaf: false,
value: 'bj',
}];

class Demo extends React.Component {
Expand All @@ -33,13 +37,18 @@ class Demo extends React.Component {
// 动态加载下级数据
setTimeout(() => {
targetOption.loading = false;
targetOption.children = [{
label: `${targetOption.label}动态加载1`,
value: 'dynamic1',
}, {
label: `${targetOption.label}动态加载2`,
value: 'dynamic2',
}];

if (targetOption.value === 'bj') {
targetOption.children = [];
} else {
targetOption.children = [{
label: `${targetOption.label}动态加载1`,
value: 'dynamic1',
}, {
label: `${targetOption.label}动态加载2`,
value: 'dynamic2',
}];
}
this.setState({
options: [...this.state.options],
});
Expand All @@ -53,6 +62,7 @@ class Demo extends React.Component {
loadData={this.loadData}
onChange={this.onChange}
changeOnSelect
notFoundContent={'无数据'}
>
<input value={this.state.inputValue} readOnly />
</Cascader>
Expand Down
16 changes: 14 additions & 2 deletions src/Menus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,22 @@ class Menus extends React.Component {
}

render() {
const { prefixCls, dropdownMenuColumnStyle } = this.props;
const { prefixCls, dropdownMenuColumnStyle, notFoundContent } = this.props;

const getItem = (options, menuIndex) => {
if (Array.isArray(options) && options.length === 0) {
return (
<li className={`${prefixCls}-menu-not-fount`}>{notFoundContent}</li>
);
}
return options.map(option => this.getOption(option, menuIndex));
};

return (
<div>
{this.getShowOptions().map((options, menuIndex) =>
<ul className={`${prefixCls}-menu`} key={menuIndex} style={dropdownMenuColumnStyle}>
{options.map(option => this.getOption(option, menuIndex))}
{getItem(options, menuIndex)}
</ul>
)}
</div>
Expand All @@ -158,6 +168,7 @@ Menus.defaultProps = {
prefixCls: 'rc-cascader-menus',
visible: false,
expandTrigger: 'click',
notFoundContent: '',
};

Menus.propTypes = {
Expand All @@ -173,6 +184,7 @@ Menus.propTypes = {
fieldNames: PropTypes.object,
expandIcon: PropTypes.node,
loadingIcon: PropTypes.node,
notFoundContent: PropTypes.string,
};

export default Menus;