简体   繁体   English

数组顺序子内的AngularJs ng-repeat数组

[英]AngularJs ng-repeat array inside array order child

I'm using angularJS to view my data. 我正在使用angularJS来查看我的数据。 My data is an array inside an array. 我的数据是数组中的数组。 I need to show the Tickets without the order of the object above(User). 我需要显示没有上面对象(User)顺序的Tickets I like to select to order later. 我想选择稍后订购。 For these example we use Date as order indicator. 对于这些示例,我们使用Date作为订单指标。

Model 模型

Array[2]
  0: Object
    UserId: 1
    Username: "firstUser"
    Tickets: Array[2]
      0: Object
        TicketId: "3"
        Date: "2014-05-11"
        Score: 100
      1: Object
        TicketId: "4"
        Date: "2014-02-11"
        Score: 100
  1: Object
     UserId: 1
     Username: "secondUser"
     Tickets: Array[1]
       0: Object
         TicketId: "1"
         Date: "2014-04-11"
         Score: 200

View 视图

[Username: firstUser   TicketId:   3]
[Username: secondUser  TicketId:   1]
[Username: firstUser   TicketId:   4]

It will be easier if you create a new array out of the existing data structure and then order the transformed array by date. 如果从现有数据结构中创建新数组,然后按日期对转换后的数组进行排序,则会更容易。 Here is a plunker demonstrating the same. 这是一个展示同样的掠夺者

Mainly, 主要是,

$scope.transform = function() {
    var transformedArray = [];
    angular.forEach($scope.samples, function(item){
      angular.forEach(item.Tickets, function(ticket){
        transformedArray.push({
          userName: item.Username, 
          ticketId: ticket.TicketId, 
          date: ticket.Date
        });
      });
    });

    return transformedArray;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM