Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在一个字段中迭代包含数组的对象_Javascript_Angular_Angular8 - Fatal编程技术网

Javascript 如何在一个字段中迭代包含数组的对象

Javascript 如何在一个字段中迭代包含数组的对象,javascript,angular,angular8,Javascript,Angular,Angular8,我想在我的angular项目中的html文件中显示一些记录。 我得到了回应- tabledata = { "employeeId":12345678, "employeeName":"John", "VehicleNumber": "LA99DU3267", "city":"Toronto", "events":[ { "date":"05/01/20", "inTime":"01:09:45",

我想在我的angular项目中的html文件中显示一些记录。 我得到了回应-

tabledata = {
   "employeeId":12345678,
   "employeeName":"John",
   "VehicleNumber": "LA99DU3267",
   "city":"Toronto", 
   "events":[
      {
         "date":"05/01/20",
         "inTime":"01:09:45",
         "OutTime":"05:13:50",       
         "hoursSpent": 20,           
      },
      {
         "date":"05/01/21",
         "inTime":"02:09:45",
         "OutTime":"06:13:50",       
         "hoursSpent": 30,
      },
      {
         "date":"05/01/22",
         "inTime":"03:09:45",
         "OutTime":"07:13:50",       
         "hoursSpent": 10,       
      },
      {
         "date":"05/01/23",
         "inTime":"04:09:45",
         "OutTime":"08:13:50",       
         "hoursSpent": 40,       
      },
   ],
}
我想在如下表中显示数据-

Empid   empname     vehicle       city      date       intime     outtime     hoursSpent
john    12345678   LA99DU3267    Toronto   05/01/20    01:09:45   05:13:50     20
john    12345678   LA99DU3267    Toronto   05/01/21    02:09:45   06:13:50     30
john    12345678   LA99DU3267    Toronto   05/01/22    03:09:45   07:13:50     10
john    12345678   LA99DU3267    Toronto   05/01/23    04:09:45   08:13:50     40
我可以使用-

<ion-row class="data-table data-table-row" *ngFor="let data of tableData.events"> 
    <ion-col class="ion-text-center cell-class" *ngFor="let item of data | keyvalue: originalOrder">
         {{ item.key  }}
     </ion-col>
 </ion-row> 

{{item.key}
但要显示对象中的值,我得不到任何解决方案

请帮忙。 提前谢谢 如果有人要将其标记为负数,请这样做,但请先帮助我


也许这是一个愚蠢的问题,但我对angular还不熟悉,所以这对我来说非常重要。

您可以使用自定义管道转换数据并将其显示出来

管道:

用法:

<ion-row class="data-table data-table-row" *ngFor="let data of tableData.events | datamap:tableData"> 
    <ion-col class="ion-text-center cell-class" *ngFor="let item of data | keyvalue: originalOrder">
         {{ item.key  }}
     </ion-col>
 </ion-row> 

{{item.key}
我不知道爱奥尼亚,我相信这会有帮助


您想知道如何使用
keyvalue
管道获取对象属性的值吗?我完全不知道如何使用keyvalue管道,但在尝试迭代对象时得到了此解决方案,这些对象可以使用tabledata直接访问。例如,tabledata.EmployeeNameMose值可以直接访问,但我还需要访问表的同一行中的数组值。如何启动for循环?
<ion-row class="data-table data-table-row" *ngFor="let data of tableData.events | datamap:tableData"> 
    <ion-col class="ion-text-center cell-class" *ngFor="let item of data | keyvalue: originalOrder">
         {{ item.key  }}
     </ion-col>
 </ion-row>