fixed tree uncheck
This commit is contained in:
parent
fa016d93f9
commit
508cd6f5bc
|
@ -35,6 +35,7 @@ export type SensorItemTreeProps = SensorItemTreeStateProps & SensorItemTreeDispa
|
|||
|
||||
export interface SensorItemTreeState {
|
||||
categoryState: Map<number, boolean>;
|
||||
categoryCheckState: Map<number, boolean>;
|
||||
itemState: Map<number, Array<boolean>>;
|
||||
}
|
||||
|
||||
|
@ -56,6 +57,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
|
||||
this.state = {
|
||||
categoryState: new Map(),
|
||||
categoryCheckState: new Map(),
|
||||
itemState: new Map(),
|
||||
};
|
||||
this.sortItemMap();
|
||||
|
@ -86,7 +88,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
this.itemMap.forEach((data: TreeItem, key: number) => {
|
||||
// this.state.itemState[key] = new Array(data.metaSensorItemList.length).fill(false);
|
||||
elems.push(
|
||||
<List.Item key={key + 1} >
|
||||
<List.Item key={key} >
|
||||
<List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'} onClick={() => {
|
||||
let newCategoryState: Map<number, boolean> = _.clone(this.state.categoryState);
|
||||
newCategoryState[key] = !newCategoryState[key];
|
||||
|
@ -94,8 +96,10 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
|
||||
}} />
|
||||
<List.Content>
|
||||
<List.Header> <Checkbox label={data.metaSensorItemType.name} onChange={
|
||||
<List.Header> <Checkbox label={data.metaSensorItemType.name} checked={this.state.categoryCheckState[key]} onChange={
|
||||
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
|
||||
|
||||
this.state.categoryCheckState[key] = checkProps.checked;
|
||||
let newItemState: Map<number, Array<boolean>> = _.clone(this.state.itemState);
|
||||
if (newItemState[key] === undefined) {
|
||||
newItemState[key] = new Array(data.metaSensorItemList.length).fill(false);
|
||||
|
@ -140,16 +144,21 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
<List.Content>
|
||||
<List.Header> <Checkbox label={item.name} checked={this.state.itemState[parentKey][idx]} onChange={
|
||||
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
|
||||
if(this.selectedItemMap[parentKey] === undefined) {
|
||||
if (this.selectedItemMap[parentKey] === undefined) {
|
||||
this.selectedItemMap[parentKey] = [];
|
||||
}
|
||||
if (checkProps.checked) {
|
||||
this.selectedItemMap[parentKey].push(item);
|
||||
} else {
|
||||
let index: number = this.selectedItemMap[parentKey].indexOf(item);
|
||||
if(index >= 0) {
|
||||
if (index >= 0) {
|
||||
this.selectedItemMap[parentKey].splice(index, 1);
|
||||
}
|
||||
if (this.selectedItemMap[parentKey].length <= 0) {
|
||||
let newCheckState: Map<number, boolean> = _.clone(this.state.categoryCheckState);
|
||||
newCheckState[parentKey] = false;
|
||||
this.setState({ categoryCheckState: newCheckState });
|
||||
}
|
||||
}
|
||||
}} /></List.Header>
|
||||
<List.Description>Sensor Item</List.Description>
|
||||
|
@ -175,6 +184,13 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
);
|
||||
}
|
||||
|
||||
private checkUnCheckParent(metaSensorItemList: Array<MetaSensorItem>): boolean {
|
||||
if (metaSensorItemList.length <= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private GetMetaSensorItemType(id: number): MetaSensorItemType {
|
||||
|
||||
for (let i: number = 0; i < SensorTypeJsonData.length; ++i) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user