修复checkboxes拉取数据无法设置全选问题

This commit is contained in:
catchonme 2019-10-25 17:01:58 +08:00
parent 832bf5843b
commit 91fb4da1c5

View File

@ -3,6 +3,7 @@ import {OptionsControl, OptionsControlProps, Option} from './Options';
import cx from 'classnames';
import Checkbox from '../../components/Checkbox';
import chunk = require('lodash/chunk');
import {difference} from '../../utils/helper';
export interface CheckboxesProps extends OptionsControlProps {
placeholder?: any;
@ -25,6 +26,27 @@ export default class CheckboxesControl extends React.Component<CheckboxesProps,
defaultCheckAll && onToggleAll();
}
componentDidUpdate(prevProps:OptionsControlProps) {
let {options: currOptions, onToggleAll, checkAll, defaultCheckAll} = this.props;
if (checkAll && defaultCheckAll && currOptions.length) {
let {options: prevOptions} = prevProps;
if (prevOptions.length != currOptions.length) {
onToggleAll();
} else {
for(let i = 0, len = currOptions.length; i < len; i++) {
let diff = difference(prevOptions[i], currOptions[i]);
let hasDifference = Object.keys(diff).length;
if (hasDifference) {
onToggleAll();
break;
}
}
}
}
}
reload() {
const reload = this.props.reloadOptions;
reload && reload();