[英]Select nested array element with restangular or angular
I seem to be having difficulty reading/querying a nested json element from an array returned from mongo/ mongoose using either restangular or angular. 我似乎在使用restangular或angular从mongo / mongoose返回的数组中读取/查询嵌套的json元素时遇到困难。
I can write to the nested elements but just not read/query. 我可以写入嵌套元素,但不能读取/查询。
To clarify the data is returned and held in the $scope.data for example. 例如,为了澄清数据返回并保存在$ scope.data中。 But how do I write restangular or angular to get the second level key & value from $scope.data.
但是,我该如何写矩形或角形以从$ scope.data获取第二级键和值。
Updated - Extra Info 更新-额外信息
This is the data within $scope.data: 这是$ scope.data中的数据:
[
{
"_id": "551528ecbb8253446cb26e4f",
"location": "London Office",
"hostname": "lon-asa-01",
"device": "Switch-MLS",
"model": "Cisco 3750",
"softwareImage": "1.2",
"serialNumber": "123456",
"subnets": [
{
"range": "10.0.100.0/24",
"type": "Client"
},
{
"range": "10.0.101.0/24",
"type": "Server"
}
],
"ipAddresses": [
{
"ipAddress": "10.0.100.1",
"type": "Inside"
},
{
"ipAddress": "10.0.101.254",
"type": "Outside"
}
]
}
]
Using angular I want to be able to {{ data.ipAddresses.ipAddress}} and {{ data.ipAddresses.type}} to get the key/value pair in the nested element so I can 使用angular我希望能够{{data.ipAddresses.ipAddress}}和{{data.ipAddresses.type}}来获取嵌套元素中的键/值对,这样我就可以
<tr>
<td>{{ data.ipAddresses.type }}</td>
<td>{{ data.ipAddresses.ipAddress }}</td>
</tr>
what you can do if you want to manipulate by $scope.data 如果要通过$ scope.data进行操作,该怎么办
<table>
<tr ng-repeat="item in data">
<td>
{{item.ipAddresses[0].ipAddresses}}
{{item.ipAddresses[0].type}}
</td>
</tr>
</table>
where item correpondonds to each element in your array 项目对应于数组中每个元素的位置
if you want to manipulate by $scope.data.ipAddresses: 如果要通过$ scope.data.ipAddresses进行操作:
<table>
<tr ng-repeat="item in data[0].ipAddresses">
<td>
{{item.ipAddresses}}
{{item.type}}
</td>
</tr>
</table>
You can use: 您可以使用:
<tr>
<td>{{ data[0].ipAddresses[0].type }}</td>
<td>{{ data[0].ipAddresses[0].ipAddress }}</td>
</tr>
Using ng-repeat: 使用ng-repeat:
<tr ng-repeat="item in data[0].ipAddresses">
<td>{{ item.type }}</td>
<td>{{ item.ipAddress }}</td>
</tr>
Thank you all for the help. 谢谢大家的帮助。
In the end this is what worked for me: Yes I know I used ul li but I was just prototyping. 最终这对我有用:是的,我知道我使用了ul li,但我只是在制作原型。
<ul ng-repeat="network in networks">
<li>{{ network._id}}</li>
<li>{{ network.location}}</li>
<li>{{ network.hostname}}</li>
<li>{{ network.device}}</li>
<li>
<ul ng-repeat="ip in network.ipAddresses">
<li>{{ ip.type }}</li>
<li>{{ ip.ipAddress }}</li>
</ul>
</li>
<li>{{ network.subnets}}</li>
<li>{{ network.iosVersion}}</li>
<li>{{ network.softwareImage}}</li>
<li>{{ network.serialNumber}}</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.