fixed item tree

This commit is contained in:
snoop 2017-12-28 16:35:54 +09:00
parent a0cd6f75b4
commit cdd79e7c07

View File

@ -17,7 +17,7 @@ export type Props = StateProps & DispatchProps;
export interface State {
dropState: Map<string, boolean>;
checkBoxState: Map<string, boolean>;
// checkBoxState: Map<string, boolean>;
checkBoxChildrenState: Map<string, Map<string, boolean>>;
}
@ -35,7 +35,7 @@ export class ItemTree extends React.Component<Props, State> {
this.state = {
dropState: new Map(),
checkBoxState: new Map(),
// checkBoxState: 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) => {
this.state.checkBoxState[key] = checkProps.checked;
private onCheckBox = (pKey: string, key: string, checkProps: CheckboxProps, data: ItemTreeObj) => {
// this.state.checkBoxState[key] = checkProps.checked;
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);
@ -97,20 +101,20 @@ export class ItemTree extends React.Component<Props, State> {
let resBool: boolean = false;
if (this.state.checkBoxState[key]) {
resBool = true;
// if (this.state.checkBoxState[key]) {
// 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;
}
@ -123,7 +127,7 @@ export class ItemTree extends React.Component<Props, State> {
let elems: JSX.Element[];
elems = this.itemRender(this.props.ItemTreeList, '');
elems = this.itemRender(this.props.ItemTreeList, 'r');
return elems;
}
@ -158,7 +162,7 @@ export class ItemTree extends React.Component<Props, State> {
{item.isCheckBox === false ? item.label :
<Checkbox label={item.label} checked={this.checkCheckBox(nkeyStr, pKeyStr) ? true : false} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
this.onCheckBox(nkeyStr, checkProps, item);
this.onCheckBox(pKeyStr, nkeyStr, checkProps, item);
}} />}
</List.Header>
<List.Description style={{ marginLeft: '26px' }}></List.Description>