mat-tree displaying child value integers as nodes
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
I am new to this so please say if this is better posted elsewhere.
I am building a mat-tree on the fly by creating a json string.
The string is:
" {"Politics":[],"Sport":[{"footie":[{"uefa":[]}]},{"sportsub":[]}],"Weather":[{"newdir":[]},{"weathersub":[]}"
It works fine but displays the child level value as an extra level, (see image) how do I lose this?
Code is
private populateTree(workdata) {
var dataObject = JSON.parse(workdata);
// Build the tree nodes from Json object. The result is a list of `FileNode` with nested
// file node as children.
const data = this.buildFileTree(dataObject, 0);
// Notify the change.
this.dataChange.next(data);
}
buildFileTree(obj: { [key: string]: any }, level: number, parentId: string = '0'): FileNode[] {
return Object.keys(obj).reduce((accumulator, key, idx) => {
const value = obj[key];
const node = new FileNode();
node.filename = key;
node.id = `${parentId}/${idx}`;
if (value != null) {
if (typeof value === 'object') {
node.children = this.buildFileTree(value, level + 1, node.id);
} else {
node.type = value;
}
}
return accumulator.concat(node);
}, []);
}

Beitragsleitfaden
Rechercherichtung
Beginne damit, das JSON in populateTree zu reproduzieren und buildFileTree nachzuverfolgen, insbesondere wie Objektwerte zu children werden und Nicht-Objekt-Werte zu node.type. Als erledigt gilt, wenn die beabsichtigte mat-tree-Hierarchie ohne den zusätzlichen Child-Value-Knoten gerendert wird; das Issue nennt keine Repository-Datei und keinen auszuführenden Test.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100