对象父键JavaScript
我使用对象父键JavaScript,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,我使用AngularJS在表格上显示一些数据,为此我使用ng repeat获取一个对象,并在表格单元格中显示它的属性值 对象结构如下所示: { ... ... "containerKey" : { "parentKey" : { "childKey1" : "value", "childKey2" : "value", "childKey3" : "value } } } ng r
AngularJS
在表格上显示一些数据,为此我使用ng repeat
获取一个对象,并在表格单元格中显示它的属性值
对象结构如下所示:
{
...
...
"containerKey" : {
"parentKey" : {
"childKey1" : "value",
"childKey2" : "value",
"childKey3" : "value
}
}
}
ng repeat显示了一个表
<table ng-repeat="key in containerKey">
<tr>
<!-- This should display the value of the key (in my case it is the name of a day in the week, but it displayed the entire object inside key.parentKey, which is expected -->
<th id="day">{{ key.parentKey }}</th> <!-- I would like for this to show the value of the key, in my case that would be the name of the day, like "monday" -->
</tr>
<tr>
<td>{{ parentKey.childKey1 }}</td>
</tr>
<tr>
<td>{{ parentKey.childKey2 }}</td>
</tr>
<tr>
<td>{{ parentKey.childKey3 }}</td>
</tr>
</table>
{{key.parentKey}
{{parentKey.childKey1}
{{parentKey.childKey2}
{{parentKey.childKey3}
如何在表单元格中仅显示parentKey的键值?考虑我使用<代码> ng重复>代码>显示多行,每行包含<天>(PARTEKEY)/< P>的<代码> NG重复> /代码>。
澄清:
我希望带有
id=“day”
的
元素显示parentKey
键的文本。th
元素的内容将是parentKey
(字符串parentKey),而不是parentKey
的值。您是否尝试更改ng repeat以使用对象表示法:
<table ng-repeat="(key, value) in containerKey">
您应该可以访问该键。您是否尝试过更改ng repeat以使用对象符号:
<table ng-repeat="(key, value) in containerKey">
您应该可以访问该键。首先,在代码中,您试图在对象上使用ng repeat。ng repeat应该迭代数组 考虑到
containerKey
是一个parentKey
数组,这可能适用于:
<table>
<tbody ng-repeat="(key, value) in containerKey">
<th>{{key}}</th>
<tr>{{value.childKey1}}</tr>
<tr>{{value.childKey2}}</tr>
<tr>{{value.childKey3}}</tr>
</tbody>
</table>
{{key}}
{{value.childKey1}
{{value.childKey2}
{{value.childKey3}
首先,在代码中,您试图在对象上使用ng repeat。ng repeat应该迭代数组
考虑到containerKey
是一个parentKey
数组,这可能适用于:
<table>
<tbody ng-repeat="(key, value) in containerKey">
<th>{{key}}</th>
<tr>{{value.childKey1}}</tr>
<tr>{{value.childKey2}}</tr>
<tr>{{value.childKey3}}</tr>
</tbody>
</table>
{{key}}
{{value.childKey1}
{{value.childKey2}
{{value.childKey3}
请澄清所需的输出。请澄清所需的输出。正确,我投票给你,因为第一个答案是由rrd给出的,所以我将及时给他正确的答案!谢谢正确,我投票给你,因为第一个答案是由rrd给出的,所以我会及时给他正确的答案!谢谢