如何在 AngularJS 中使用 ng-repeat 迭代键和值? [英] How to iterate over the keys and values with ng-repeat in AngularJS?

查看:19
本文介绍了如何在 AngularJS 中使用 ng-repeat 迭代键和值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中,我有如下数据:$scope.object = 数据

In my controller, I have data like: $scope.object = data

现在这个数据是包含来自 json 的键和值的字典.

Now this data is the dictionary with keys and values from json.

我可以使用模板中的 object.name 访问该属性.有什么方法可以迭代键并将它们显示在表格中

I can access the attribute with object.name in the template. Is there any way that I can iterate over the keys as well and display them in table like

<代码>{{key}} </td><td>data.key </td>

数据是这样的

{
    "id": 2,
    "project": "wewe2012",
    "date": "2013-02-26",
    "description": "ewew",
    "eet_no": "ewew",
}

推荐答案

怎么样:

<table>
  <tr ng-repeat="(key, value) in data">
    <td> {{key}} </td> <td> {{ value }} </td>
  </tr>
</table>

此方法在文档中列出:https://docs.angularjs.org/api/ng/directive/ngRepeat

这篇关于如何在 AngularJS 中使用 ng-repeat 迭代键和值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆