想要根据angularJS中父元素的id链接外键的元素和显示项

时间:2016-07-29 15:43:59

标签: javascript angularjs json html5

我有一个喜欢

的json
     $scope.posts = [
{postId:'1',title: 'Beautiful Restaurant',topic: 'Beautiful Restaurant', upvotes: 5, rating:1, image:'img/restaurant1.jpg',
  comments: [
{commentId:'11',postId:'1',author: 'Joe', body: 'Cool post!', upvotes: 6},
{commentId:'12',postId:'1',author: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 2}
   ]}

这是HTML部分      

<h3>{{post.title}}</h3>
<p>{{post.topic}}</p>
<img ng-src="{{post.image}}"  /><br>
<div><button ng-click="incrementUpvotes(post)">Like</button>
  Upvotes: {{post.upvotes}}<div class="star-rating" star-rating rating-     value="post.rating" data-max="5" on-rating-selected="rateFunction(post.rating)">   </div>
 </div>
<span>
 <input type="button" value="Show Comments" ng-click="ShowHide()" />
 </span>
     <div ng-hide = "IsHidden" ng-repeat="comment in post.comments  | orderBy:'-upvotes'" >

          <span class="glyphicon glyphicon-thumbs-up"
            ng-click="incrementUpvotes(comment)">+</span>
          {{comment.upvotes}} - by {{comment.author}}
          <span style="font-size:20px; margin-left:10px;">{{comment.body}}</span>
          <form ng-submit="addComment()">
          <h3>Add a new comment</h3>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Comment" ng-model="body"></input>
          </div>
          <button type="submit" class="btn btn-primary">Post</button>
        </form>
        </div>
   </div>

想在点击时显示特定帖子的评论。基本上,我想将评论与特定帖子联系起来。不知道如何。如果有人可以显示类似的示例或编辑帮助我使用代码。

0 个答案:

没有答案