fixed item tree
This commit is contained in:
parent
a0cd6f75b4
commit
cdd79e7c07
|
@ -17,7 +17,7 @@ export type Props = StateProps & DispatchProps;
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
dropState: Map<string, boolean>;
|
dropState: Map<string, boolean>;
|
||||||
checkBoxState: Map<string, boolean>;
|
// checkBoxState: Map<string, boolean>;
|
||||||
checkBoxChildrenState: Map<string, Map<string, boolean>>;
|
checkBoxChildrenState: Map<string, Map<string, boolean>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ export class ItemTree extends React.Component<Props, State> {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
dropState: new Map(),
|
dropState: new Map(),
|
||||||
checkBoxState: new Map(),
|
// checkBoxState: new Map(),
|
||||||
checkBoxChildrenState: new Map(),
|
checkBoxChildrenState: new Map(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,10 +70,14 @@ export class ItemTree extends React.Component<Props, State> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private onCheckBox = (key: string, checkProps: CheckboxProps, data: ItemTreeObj) => {
|
private onCheckBox = (pKey: string, key: string, checkProps: CheckboxProps, data: ItemTreeObj) => {
|
||||||
this.state.checkBoxState[key] = checkProps.checked;
|
// this.state.checkBoxState[key] = checkProps.checked;
|
||||||
let newCheckBoxChildrenState: Map<string, Map<string, boolean>> = _.clone(this.state.checkBoxChildrenState);
|
let newCheckBoxChildrenState: Map<string, Map<string, boolean>> = _.clone(this.state.checkBoxChildrenState);
|
||||||
|
|
||||||
|
if(newCheckBoxChildrenState.get(pKey) === undefined) {
|
||||||
|
newCheckBoxChildrenState.set(pKey, new Map());
|
||||||
|
}
|
||||||
|
newCheckBoxChildrenState.get(pKey).set(key, checkProps.checked);
|
||||||
|
|
||||||
this.reverseChildrenCheck(data.children, key, checkProps, newCheckBoxChildrenState);
|
this.reverseChildrenCheck(data.children, key, checkProps, newCheckBoxChildrenState);
|
||||||
|
|
||||||
|
@ -97,20 +101,20 @@ export class ItemTree extends React.Component<Props, State> {
|
||||||
|
|
||||||
let resBool: boolean = false;
|
let resBool: boolean = false;
|
||||||
|
|
||||||
if (this.state.checkBoxState[key]) {
|
// if (this.state.checkBoxState[key]) {
|
||||||
resBool = true;
|
// resBool = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (pKey !== '') {
|
||||||
|
|
||||||
|
let childrenState: Map<string, boolean> = this.state.checkBoxChildrenState.get(pKey);
|
||||||
|
|
||||||
|
if (childrenState !== undefined) {
|
||||||
|
let b: boolean = childrenState.get(key);
|
||||||
|
resBool = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pKey !== '') {
|
// }
|
||||||
|
|
||||||
let childrenState: Map<string, boolean> = this.state.checkBoxChildrenState.get(pKey);
|
|
||||||
|
|
||||||
if (childrenState !== undefined) {
|
|
||||||
let b: boolean = childrenState.get(key);
|
|
||||||
resBool = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return resBool;
|
return resBool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +127,7 @@ export class ItemTree extends React.Component<Props, State> {
|
||||||
|
|
||||||
let elems: JSX.Element[];
|
let elems: JSX.Element[];
|
||||||
|
|
||||||
elems = this.itemRender(this.props.ItemTreeList, '');
|
elems = this.itemRender(this.props.ItemTreeList, 'r');
|
||||||
|
|
||||||
return elems;
|
return elems;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +162,7 @@ export class ItemTree extends React.Component<Props, State> {
|
||||||
{item.isCheckBox === false ? item.label :
|
{item.isCheckBox === false ? item.label :
|
||||||
<Checkbox label={item.label} checked={this.checkCheckBox(nkeyStr, pKeyStr) ? true : false} onChange={
|
<Checkbox label={item.label} checked={this.checkCheckBox(nkeyStr, pKeyStr) ? true : false} onChange={
|
||||||
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
|
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
|
||||||
this.onCheckBox(nkeyStr, checkProps, item);
|
this.onCheckBox(pKeyStr, nkeyStr, checkProps, item);
|
||||||
}} />}
|
}} />}
|
||||||
</List.Header>
|
</List.Header>
|
||||||
<List.Description style={{ marginLeft: '26px' }}></List.Description>
|
<List.Description style={{ marginLeft: '26px' }}></List.Description>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user