I am unsure if this has got anything to do with AngularJS at all and if it is only JSON related.

不管怎样,让我们假设我们有以下JSON:

$scope.dataSets = {
    "names": ["Horace", "Slughorn", "Severus", "Snape"],
    "genders": ["Male", "Female"]
}

现在,我使用ng-Repeat指令打印上述内容,如下所示:

<div ng-repeat="data in dataSets>
    //Continue readig to know what I am expcting here
</div>

我希望在<div></div>个标签中打印"姓名"和"性别".也就是说,我希望打印JSON的密钥.我不知道 keys 是什么,因为它们可能是任何东西.我该怎么做?

推荐答案

正如文件所说的那样:

(key, value) in expression – where key and value can be any user defined identifiers, and expression is the scope expression giving the collection to enumerate.

<div ng-repeat="(key, data) in dataSets">
  {{key}}
</div>

Json相关问答推荐

使用SQL查询从SON中查找第n个密钥对值

使用JSONata将具有相同键的字典合并

Golang JSON Date Tim.Date()测试请求

从Razor Pages的AJAX Json呈现DataTables问题.Net GET

SWIFT中的网络经理

在MongoDB中检索某个月份和年份的JSON文档

如何将响应数据保存到Flutter 中的共享首选项中

从Postgres表中的JSON中提取值

jq :遍历 json 并在键存在时检索集合

jolt 通配符如何用于 RHS?

使用 json 值过滤 Django 模型

序列化为json时如何忽略空列表?

JBuilder中未定义的局部变量或方法json

在视图中将 .Net 对象转换为 JSON 对象

ASP.NET Core API 仅返回列表的第一个结果

Microsoft.Net.Http 与 Microsoft.AspNet.WebApi.Client

使用 axios 在 POST multipart/form-data 请求中发送文件和 json

从 JSON 到 JSONL 的 Python 转换

使用 JSONArray 和 JSONObject 进行 Foreach

如何从 github API 解析链接头