如何获取Angular 2模板中json对象的长度
How to get the length of the json object in Angular 2 template
我有一个这样的 json 数组。
[
{
"variations": {
"title": {
"newValue": "test new value1",
"oldValue": "test old value1"
}
}
},
{
"variations": {
"data": {
"newValue": "new data",
"oldValue": "httpold data"
},
"length": {
"newValue": "48",
"oldValue": "9.00"
}
}
}
]
由此我想获得 Html 中变化的长度以及要查看的渲染和值。
<table class="table table-bordered table-hover">
<thead class="table-title">
<tr>
<th class="text-center">Field count</th>
<th class="text-center">Field Name</th>
<th class="text-center">Old Value</th>
<th class="text-center">New Value</th>
</tr>
</thead>
<tbody *ngFor="let data of datas">
<tr>
<td class="text-left" rowspan="2">{{data.variations.length}}</td>
<td class="text-left" rowspan="2"></td>
<td class="text-left" rowspan="2"></td>
</tr>
<tr>
</tr>
</tbody>
</table>
在上面的代码中,我如何获得 length
的 variation
数据。还需要渲染并显示所有新字段和旧字段值到视图。
谁能帮帮我
组件端:
objectKeys = Object.keys;
模板端:
<tbody *ngFor="let data of datas">
<tr>
<td class="text-left" rowspan="2">{{objectKeys(data.variations).length}}</td>
...
</tr>
...
</tbody>
我有一个这样的 json 数组。
[
{
"variations": {
"title": {
"newValue": "test new value1",
"oldValue": "test old value1"
}
}
},
{
"variations": {
"data": {
"newValue": "new data",
"oldValue": "httpold data"
},
"length": {
"newValue": "48",
"oldValue": "9.00"
}
}
}
]
由此我想获得 Html 中变化的长度以及要查看的渲染和值。
<table class="table table-bordered table-hover">
<thead class="table-title">
<tr>
<th class="text-center">Field count</th>
<th class="text-center">Field Name</th>
<th class="text-center">Old Value</th>
<th class="text-center">New Value</th>
</tr>
</thead>
<tbody *ngFor="let data of datas">
<tr>
<td class="text-left" rowspan="2">{{data.variations.length}}</td>
<td class="text-left" rowspan="2"></td>
<td class="text-left" rowspan="2"></td>
</tr>
<tr>
</tr>
</tbody>
</table>
在上面的代码中,我如何获得 length
的 variation
数据。还需要渲染并显示所有新字段和旧字段值到视图。
谁能帮帮我
组件端:
objectKeys = Object.keys;
模板端:
<tbody *ngFor="let data of datas">
<tr>
<td class="text-left" rowspan="2">{{objectKeys(data.variations).length}}</td>
...
</tr>
...
</tbody>