ng重复2个数组,它们之间有一个关系

时间:2016-10-03 11:04:03

标签: angularjs arrays web-services

将2个Web服务调用到一个数组中,这是

  1. 发布webservice
  2. 评论网络服务
  3. 假设我有2个帖子,每个帖子分别有3个和2个评论。

    每条评论都有帖子ID

    例如: 后阵列: [object1,object2] - 这里的帖子是在

    中有数据的对象
    {"_identifier":"","_entityName":"CRM_Posts","$ref":"CRM_Posts\/FE8B8DEDBC874F61BA255395C1A07BEE","id":"FE8B8DEDBC874F61BA255395C1A07BEE","liveTransfer":null,"client":"7F3CD06A9B334C5FBED095907D8837A8","client$_identifier":"Ocala\/Fasho Group","organization":"0","organization$_identifier":"*","active":true,"creationDate":"2016-09-24T15:19:37+05:30","createdBy":"436703728E15455D80ED1319C5C7BE9F","createdBy$_identifier":"Tayyab Sayyad","updated":"2016-09-24T15:19:37+05:30","updatedBy":"436703728E15455D80ED1319C5C7BE9F","updatedBy$_identifier":"Tayyab Sayyad","message":"What About This Shipment !","userContact":"9F3332D3D9AA401EACA3AC3B4C684D7F","userContact$_identifier":"Ocala","table":"147718EA960A4BCDBEE9C172E6D7048F","table$_identifier":"OCA_Shippingorder","recordID":"1B3A9D1FDAC84E169060DC2CA216BE76","recordTime":1475492220402}
    

    同样评论 ARRAY0 [object1,Object2的], ARRAY1 [object1,Object2的,object3]

    现在我需要以这样的方式迭代

    示例:

    Post2:      注释1      注释2      将comment3 post1:      注释1      注释2

    我希望我能清楚地解释我的目标,并需要参考来实现这个

1 个答案:

答案 0 :(得分:1)

你可以嵌套重复:

<div ng-repeat="post in posts">
{{ post.field }}
    <div ng-repeat="comment in getComments(post.id)">
    {{ comment.field }}
    </div>
</div>

然后使用函数来过滤您的Web服务返回的内容:

$scope.getComments = function(postId) {
    return $scope.posts.filter(function(x) { return x.postId == postId; });
};