mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
修复checkboxes拉取数据无法设置全选问题
This commit is contained in:
parent
832bf5843b
commit
91fb4da1c5
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user