我有一个名为“帖子”的列表,其中包含如下对象。
{_id: "559301710de9c23407b237ee"
author: {user_id: "557c6922925a18a81930d2ce", username: "test"}
comment_id: []
content: "<p>123</p>"
created_at: "2015-06-30T20:52:01.738Z"
image_id: []
like_user_id: ["557c6922925a18a81930d2ce"]
likes: 1
tags: [{_id: "558ded1b8526b45407fd0bb1", tag_name: "1"}, {_id: "559301630de9c23407b237ec", tag_name: "2"},…]
title: "123"}
我想提取 tag_name 并在 html 中显示
<a ng-repeat="post in bests" ng-href="/post/{{post._id}}">
<em class="tag">{{post.tags.tag_name}}</em> //This appearently doesn't work!
<span>{{post.title}}</span>
<em class="likes">+{{post.likes}}</em>
<time>{{post.created_at}}</time>
</a>
除了 tag_name 之外一切正常。
我尝试在 ng-repeat 中使用 ng-repeat,但它似乎不起作用。你是怎么做到的?
最佳答案
尝试
<em class="tag" ng-repeat="tag in post.tags">{{tag.tag_name}}</em>
post.tags 是一个数组,所以显示 tag_names 的最简单方法是使用 ng-repeat...
关于javascript - 如何以 Angular 绑定(bind)对象中的嵌套列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31148430/