我想用以下json进行嵌套的ng-repeat:
[
{
"id": 18,
"title": "awesome title",
"description": "incredible description meow",
"hour": "2000-01-01T11:12:00.000Z",
"duration": 12,
"date": "2015-11-25",
"user_id": 1,
"latitude": 14.8744239,
"longitude": 4.1433319,
"formatted_addres": "castellgal",
"tags": [
{
"id": 29,
"name": "megatag",
"created_at": "2015-11-26T11:57:03.421Z",
"updated_at": "2015-11-26T11:57:03.421Z"
},
{
"id": 30,
"name": "another-tag",
"created_at": "2015-11-26T11:57:03.426Z",
"updated_at": "2015-11-26T11:57:03.426Z"
}
],
"username": "Shanna Friesen",
"url": "http://localhost:3000/events/18.json"
}
]
这是我的HTML代码:
<section ng-repeat="event in events | orderBy:'date'">
<div class="panel panel-default single-event">
<div class="panel-heading">
<h3>
{{event.title}}
<em class="pull-right">Created by user: {{event.username}}</em>
</h3>
</div>
<div class="panel-body">
Description:<br>{{event.description}} <br>
<em class="pull-right">{{event.date | date:'dd-MM-yyyy' }} - {{event.hour | date:"H:mm"}}</em> <br>
{{event.duration}} minutes <br>
<tr>
<td ng-repeat="tag in event.tags">{{ tag.name }}</td>
</tr>
</div>
</div>
</section>
事件已完美列出,但{{tag.name}}未显示。 如果我尝试{{event.tags}},我会看到包含所有内容的对象标记,如果我尝试{{event.tags [0] .name}},我会看到第一个标记的名称(两者都没有ng-repeat )。 但是{{tag.name}}没有显示任何内容。
感谢。
答案 0 :(得分:2)
tr
和td
标记未嵌套在table
标记内,并且您使用了events.tags而不是event.tags
<table>
<tr>
<td ng-repeat="tag in event.tags">{{ tag.name }}</td>
</tr>
<table>
这是一个有效的fiddle。
答案 1 :(得分:1)
尝试删除事件结束时的s
<td ng-repeat="tag in event.tags">{{ tag.name }}</td>