javascript - 选择具有矩形或 Angular 嵌套数组元素

标签 javascript angularjs mongodb mongoose restangular

我似乎很难使用 Restangle 或 Angular 从 mongo/mongoose 返回的数组中读取/查询嵌套的 json 元素。

我可以写入嵌套元素,但不能读取/查询。

为了澄清数据被返回并保存在 $scope.data 中。但是我如何编写 reangular 或 Angular 来从 $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"
        }
    ]
}
]

使用 Angular,我希望能够 {{ data.ipAddresses.ipAddress}} 和 {{ data.ipAddresses.type}} 获取嵌套元素中的键/值对,这样我就可以

<tr>
    <td>{{ data.ipAddresses.type }}</td>
    <td>{{ data.ipAddresses.ipAddress }}</td>
</tr>

最佳答案

如果你想通过$scope.data进行操作,你可以做什么

<table>
  <tr ng-repeat="item in data">
    <td>
     {{item.ipAddresses[0].ipAddresses}}
     {{item.ipAddresses[0].type}}

    </td>
  </tr>
</table>

其中项目对应于数组中的每个元素

如果你想通过$scope.data.ipAddresses进行操作:

<table>
  <tr ng-repeat="item in data[0].ipAddresses">
    <td>
     {{item.ipAddresses}}
     {{item.type}}

    </td>
  </tr>
</table>

关于javascript - 选择具有矩形或 Angular 嵌套数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29296513/

相关文章:

mongodb - 使用 MongoDB 在子文档中查找项目

mongodb - Nodejs/ Mongoose : connect to db that's using replica sets

javascript - Jquery - 如何在 html 中输出 "$(this).val()"

angularjs - ng-bind-html 给出一个无限的摘要错误 ($rootScope.infdig)

get - 如何使用AngularJS删除GET参数?

angularjs - 如何在 Angular JS 中取消挂起的 API 调用

javascript - 如何从子类调用父类(super class)中的 getter/setter?

javascript - i18nextify 不翻译为 javascript 函数

javascript - Nuxt,将 Vuex 存储拆分为单独的文件会出现错误 : unknown mutation type: login

mongodb - 从对象数组 MongoDB 获取不同的值