之前我執行「的父母,孩子的」來自同一類派生的幾個對象之間的關係。角打字稿:將對象作爲另一個對象的屬性的定義
我的類(模型)如下:
export class Node {
public name: string;
public isLocked: boolean;
public canBeUnlocked: boolean;
public parentNodes: Node[];
public childNodes: Node[];
}
在我的部分我聲明瞭該模型得到的幾個對象,但他們的純聲明之前的一些對象是使用對象:
Test.component.ts
import { Component, OnInit } from '@angular/core';
import {Node} from '../models/node.model';
@Component({
selector: 'app-mage',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
NodesList= [];
Node1: any;
Node2: any;
Node3: any;
Node4: any;
Node5: any;
Node6: any;
constructor() {
this.Node1 = new Node('Node1', false, true , null, [this.Node2]);
this.Node2 = new Node('Node2', true, true, [this.Node1], [this.Node3 , this.Node4]);
this.Node3 = new Node('Node3', true, false , [this.Node2], [this.Node5]);
this.Node4 = new Node('Node4', true, false , [this.Node2], [this.Node6]);
this.Node5 = new Node('Node5', true, false , [this.Node3], null);
this.Node6 = new Node('Node6', true, false , [this.Node4], null);
// The list
this.NodesList = [this.Node1, this.Node2, this.Node3 , this.Node4 , this.Node5 , this.Node6];
}
ngOnInit() {
console.log(this.Node2);
console.log(this.NodesList);
}
}
的概率LEM,與「子節點」,
例如爲節點1:節點2是一個子節點,但它的調用console.log(Node1)
時得到「未定義」,也許是因爲我」打電話是節點2作爲Node1上的屬性,定義節點2 本身之前。
問題與其他節點發生類似。
任何想法來處理? 建議?