Материал tree-light не загружает данные - PullRequest
0 голосов
/ 05 августа 2020

Сначала я успешно загрузил дерево районов, зданий и дверей, используя фиктивные данные следующим образом:

this.building = new Building(1,1,"Le batiment","l4","la rue","24","le bailleur");
this.district = new District(0,1,1,"quartier","92400","paris");
this.districts.push(this.district);
console.log(this.districts);
this.districts.forEach(district => {
  console.log(district);
  this.nodeC = new districtNodeImpl(false,null,null,new Door(1,1,"2","3","someInfo"),null);
  this.nodelast.push(this.nodeC);
  this.nodeB = new districtNodeImpl(false,null,this.building,null,this.nodelast);
  this.nodes.push(this.nodeB);
  this.node = new districtNodeImpl(false,district,null,null,this.nodes);
  this.dataSource.push(this.node);
  console.log(this.dataSource);
});

при регистрации this.dataSource я получаю:

console.log

tree

But when loading data from the server and creating my nodes the same way . the tree won't show and when logging my nodes array i get :

Code :

await this.districtDataService.getDistrictData().toPromise().then(response => {
   this.districts = response.results as District[];
 }).finally(async () => {
   for (const district of this.districts){
      await this.districtDataService.getBuildingsOfDistrict(district.id).toPromise().then(response => {
      this.buildings = response.results as Building[];
     }).finally(async ()=> {
        for(const building of this.buildings){
          await this.districtDataService.getDoorsOfBuilding(building.id).toPromise().then(response => {
            this.doors = response.results as Door[];
          }).finally(async () => {
              for(const door of this.doors){
                  await this.doorNodes.push(new districtNodeImpl(false,null,null,door,null));
              }
          })
         await this.buildingNodes.push(new districtNodeImpl(false,null,building,null,this.doorNodes));
        }
     })
     this.node = new districtNodeImpl(false,district,null,null,this.buildingNodes);
     await this.dataSource.push(this.node);
     console.log(this.dataSource);
     this.buildingNodes = new Array();
     this.doorNodes = new Array();
   }
 });

введите описание изображения здесь

Я знаю, что у моего компьютера нет причин лгать, но в то же время я не могу понять, что я делаю не так. Кто-нибудь был там раньше?

РЕДАКТИРОВАТЬ: НЕОЖИДАННО! Но это как-то связано со всем ожиданием, которое вы видите в коде. Удаление их заставляет дерево снова работать. Но я не уверен, как я могу все это перекодировать без ожидания. Кто-нибудь может хотя бы объяснить, почему это происходит?

...