最后我解决了这个问题,我在这个地方写了一个示例
如何解决?
正如我所猜测的;我必须在 'buildFileTree()' 和 'transformer()' 中写一些更改。
buildFileTree(obj: {[key: string]: any}, level: number): TodoItemNode[] {
return Object.keys(obj).reduce<TodoItemNode[]>((accumulator, key) => {
const item = obj[key];
const node = new TodoItemNode();
node.label = obj[key].name;
node.id = obj[key].id;
node.isChecked= obj[key].isChecked;
node.claimId= obj[key].claimId;
node.isPlanType= obj[key].isPlanType;
if (item != null) {
if (typeof item === 'object' && item.children!= undefined) {
node.children = this.buildFileTree(item.children, level + 1);
} else {
node.label = item.name;
}
}
return accumulator.concat(node);
}, []);}
transformer = (node: TodoItemNode, level: number) => {
const existingNode = this.nestedNodeMap.get(node);
const flatNode = existingNode && existingNode.label === node.label
? existingNode
: new TodoItemFlatNode();
flatNode.label = node.label;
flatNode.level = level;
flatNode.id=node.id;
flatNode.isChecked = node.isChecked;
flatNode.claimId = node.claimId;
flatNode.isPlanType = node.isPlanType;
flatNode.expandable = !!node.children;
this.flatNodeMap.set(flatNode, node);
this.nestedNodeMap.set(node, flatNode);
return flatNode; }