Я создаю дерево из angular материала и angular 9.
Демо
, но у меня проблема. у меня есть предметы в моих предметах, у меня может быть ребенок или нет.
, когда я создаю дерево, все элементы, у которых нет дочерних элементов, выбираются заранее, но мне не нужно это делать.
rolesToTree(roles): void {
console.log(JSON.stringify(roles))
const selections: ItemFlatNode[] = [];
const controllers = [];
roles.forEach(element => {
const attrs = [];
element['children'].forEach(attr => {
const secAttrs = [];
attr['children'].forEach(sec => {
const secAction = { name: sec['title'], actionId: sec['id'] };
secAttrs.push(secAction);
if (sec['selected'] === true) {
const a = new ItemFlatNode(false, sec['id'], sec['title'], 3);
selections.push(a);
}
});
if (attr['selected'] === true) {
const a = new ItemFlatNode(false, attr['id'], attr['title'], 2);
selections.push(a);
}
const actionss = { name: attr['title'], actionId: attr['id'], children: secAttrs };
attrs.push(actionss);
});
const controller = { name: element['title'], actionId: element['id'], children: attrs };
controllers.push(controller);
});
// this.checklistSelection = new SelectionModel<ItemFlatNode>(true, selections);
this.defualtSelected = selections;
const data = [{ name: 'All', actionId: 'sds', children: controllers }];
this.database.dataChange.next(this.database.builTree(data, 0));
}
В чем проблема? как я могу решить эту проблему ????