Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Por qué ng2-tree se muestra indefinido

Estoy usando ng2-tree https://angular2-tree.readme.io/v3.2.0/docs/inputs

Cuando ingreso debajo de json , se muestra como indefinido

 [ { "value": "helper", "name": "helper", "children": [] }, { "value": "taxi", "name": "taxi", "children": [] }, { "value": "Cake", "name": "Cake", "children": [ { "name": "Chocolate Fudge Cake", "value": "Chocolate Fudge Cake" }, { "name": "Carrot & Walnut Cake", "value": "Carrot & Walnut Cake" } ] } ]

con json anterior, mi resultado es undefined , puede verlos en mi enlace proporcionado a continuación

aquí está el enlace de stackblitz: https://stackblitz.com/edit/angular-ng2-tree-aouyza?file=app/app.component.ts

Por favor ayúdenme gracias de antemano!!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su estructura de datos es incorrecta. El componente de tree recibió como parámetro de entrada un TreeModel y tiene una matriz de TreeModel en este momento.

O ajusta su estructura de datos y usa un TreeModel padre para envolver sus actuales como sus hijos, como sigue:

 tree: TreeModel = { value: 'Parent Model', children: [ { value: 'helper', name: 'helper', children: [], }, { value: 'taxi', name: 'taxi', children: [], }, { value: 'Cake', name: 'Cake', children: [ { name: 'Chocolate Fudge Cake', value: 'Chocolate Fudge Cake', }, { name: 'Carrot & Walnut Cake', value: 'Carrot & Walnut Cake', }, ], } ] };

O itera sobre la matriz en el HTML y usa múltiples componentes de tree . Eso se vería como sigue:

 <tree [tree]="t" *ngFor="let t of tree"></tree>

Para obtener más información, consulte la página de Github de ng2-tree ;)

Actualizar:

Todavía necesita ajustar el modelo de datos de la manera que sugerí, pero puede ocultar el nodo raíz vacío. Para hacerlo, debe hacer lo siguiente:

HTML

 <tree [tree]="tree" [settings]="{ rootIsVisible: false }"></tree>

Debido a esta configuración, se aplica una clase rootless que oculta el nodo raíz empyt, pero solo si agregó node_modules/ng2-tree/styles.css a su angular.json o si agregó una implementación personalizada para esa clase.

Puede encontrar el documento de configuración aquí .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!