Json 角度:显示XDB API的结果
我正在接收返回以下数据的XDB API。我需要在表格中以角度显示这些数据,但我不知道怎么做。我应该把它当作一个物体吗?或者作为一个数组?有人知道有没有一个例子吗?我的角度是9 组成部分:Json 角度:显示XDB API的结果,json,angular,influxdb,Json,Angular,Influxdb,我正在接收返回以下数据的XDB API。我需要在表格中以角度显示这些数据,但我不知道怎么做。我应该把它当作一个物体吗?或者作为一个数组?有人知道有没有一个例子吗?我的角度是9 组成部分: listaCBS_CPU: listaCBSCPU = new listaCBSCPU(); //definition listadoCBS_CPU(){ this.cbsServicio.getListadoCBS_CPU
listaCBS_CPU: listaCBSCPU = new listaCBSCPU(); //definition
listadoCBS_CPU(){
this.cbsServicio.getListadoCBS_CPU ()
.subscribe( (respuesta:any) => {
this.listaCBS_CPU = respuesta;
});
}
服务cbsServicio.Service.ts:
getListadoCBS_CPU(){
return this.httpClient.get(`${this.PHP_API_SERVER_INFLUX}&q=SELECT * FROM "apache" WHERE ("host" = \'ax14565.com\') fill(null) LIMIT 3`);
}
结果控制台.log:
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "apache",
"columns": [
"time",
"host",
"BusyWorkers",
"server"
],
"values": [
[
"2020-08-19T07:41:40Z",
"775.com",
2,
"localhost"
],
[
"2020-08-19T07:41:50Z",
"633775.com",
2,
"localhost"
],
[
"2020-08-19T07:42:00Z",
"oc103.com",
2,
"localhost"
]
]
}
]
}
]
}
我应该如何在HTML中显示这些内容以查看“值”的结果?convertData(列:string[],data[]){
常量数据=[]
for(设i=0;i{
this.listaCBS_CPU=respuesta;
this.dataSource=this.convertData(respestua[0].series.columns,respestua[0].series.values
});
}
在html中
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Time Column -->
<ng-container matColumnDef="time">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.time}} </td>
</ng-container>
...
</table>
不
{{element.time}
...
您只需将整个json转换为有效的dataSource
还可以考虑一个变量,用于保存列名
以下是关于stackoverflow这个主题的许多答案:
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Time Column -->
<ng-container matColumnDef="time">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.time}} </td>
</ng-container>
...
</table>