如何编写多个对象数据

时间:2018-06-09 07:55:34

标签: angular typescript

我想编写基于Angular对象的数据,如此格式

records: Array<any>;
 ngOnInit(){
    this.records= [
      { CategoryID: 1,  CategoryName: "Beverages", Description: "Coffees, teas" },   ];
     "Employee"={
            //Here How can i write Employee Data
     }

我需要this.records.Employee.Id的数据。

1 个答案:

答案 0 :(得分:0)

让Employee成为子对象。

this.records= [

   record1:  { CategoryID: 1,  
               CategoryName: "Beverages", 
                Description: "Coffees, teas",
                 Employee: 
                          {
                               Id: 123,
                               name: "John Doe"
                          }
               }
]

现在以这种方式访问​​id

 this.records.['record1'].Employee.Id

 this.records.[0].Employee.Id