Jstree no casrga children

0

I am trying to load a jstree by means of a json array created from multiple queries, the problem is that I generate the JSON with the structure that requires it according to the documentation, but when I execute the code it only loads the two nodes parents and children, no, here is my code I hope you can help me

This is typescript

   import { Component, OnInit } from '@angular/core';
import { ScriptLoaderService } from '../../../../_services/script-loader.service';
import { textoModuloAdm } from '../../../../texto';
import { Router } from "@angular/router";
import { AjaxService } from '../../../../_services/ajax.service';

import *  as TreeView from '../../../../../assets/js/treeViewRol';

@Component({
  selector: 'app-form-rol',
  templateUrl: './form-rol.component.html',
  styles: []
})
export class FormRolComponent implements OnInit {
  treeView: TreeView.TreeView = new TreeView.TreeView([], false);

  constructor(
    private _script: ScriptLoaderService,
    public texto: textoModuloAdm,
    private router: Router,
    private ajax_s: AjaxService,
  ) { }

  ngOnInit() {

    this.obtenerInformacionInicial().then((data: any) => {
      return new Promise((resolve, reject) => {
        data.forEach((item) => {
          let child = [];
          let url = 'private/Permiso_Mod/' + item.id;
          console.log(url);
          this.ajax_s.getInfo(url, '').subscribe((modulos: any) => {
            modulos.result[0].forEach((modulo) => {

              child.push({
                //"id": modulo.idModulo,
                "text": modulo.nombreModulo,
                "parent": item.id
                //"icon": "icon-null",
              })
            })
            item.children = child;
          })
        })
        //console.log(data);
        resolve(data);
      }).then((tree) => {
        this.treeView.cargarTreeView({
          "core": {
            "data": tree
          },
          plugins: ["dnd", "state", "types", "checkbox"]
        });
      })

    })
  }

  obtenerInformacionInicial() {
    return new Promise((resolve, reject) => {

      this.ajax_s.getInfo('private/Modulo', '').subscribe((data) => {

        let modulos = data.result[0];
        let tree = [];
        let url = '';

        modulos.forEach((value, index) => {
          if (value.posicion.indexOf('.') == -1) {
            tree.push({
              //"id":'mod'+value.idModulo.toString(),
              //"id": "#",
              "text": value.nombreModulo,
              "parent": '#',
              "children": [],
              "icon": "fa fa-folder m--font-folderRol",
            })
          }

        })


        resolve(tree)

      })


    })

  }


y en el javascript esoty haciendo esto 

    cargarTreeView(tree) {
        console.log(tree);
        $('#treeViewRol').jstree(tree);
    }

PDTA: The Json that I am generating is this:

    
asked by Daniel 01.10.2018 в 23:08
source

1 answer

0
0:{id: 1, text: "Sistema", parent: "#"}
1:{id: 2, text: "Activo fijo", parent: 1}
2:{id: 3, text: "Transacciones", parent: 2}

This is an example of a json that I used to fill a jsTree, I see that in your code the id property you have commented on and that is the indicator to know the parent node and make a connection with the property parent , in my case System is the main node, fixed asset your child and transactions the grandchild.

    
answered by 02.10.2018 в 15:51