artículos en árbol pre-seleccionado en el material angular 9 y angular

mr codificador:

i crear árbol en el material angulares y 9 angular.

Manifestación

pero tengo un problema . tengo artículos en mis artículos Mi ser tiene hijos o no.

cuando creo un árbol cada artículo en no haber ninguna get niño pre-seleccionados, pero no necesito hacer esto.

    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));
}

Cuál es el problema ? Como puedó resolver esté problema ????

Gourav Garg:

verifica método descendantsAllSelected para cada nodo secundario se selecciona, que devolverá verdadero si no hay ningún elemento descendiente.

Para corregir esto, necesidad de comprobar para la longitud descendientes y si ese es 0, el nodo de nodo de retorno valor seleccionado.

Actualización descendantsAllSelected método de la siguiente manera:

    descendantsAllSelected(node: ItemFlatNode): boolean {
       const descendants = this.treeControl.getDescendants(node);
       return (this.checklistSelection.isSelected(node) && descendants.length==0) || (descendants.length>0 && descendants.every(child => this.checklistSelection.isSelected(child)));
     }

Supongo que te gusta

Origin http://10.200.1.11:23101/article/api/json?id=406199&siteId=1
Recomendado
Clasificación