可以通过数组元素来排序对象数组吗?

时间:2013-07-22 04:54:24

标签: angularjs angularjs-ng-repeat

如果我有这样的数组:

[
  {names: [
     {firstName: "Bob", lastName: "Jones"},
     {firstName: "Martha", lastName: "Jones"}
   ]
  },
  {names: [
     {firstName: "Jim", lastName: "Franklin"},
     {firstName: "Jill", lastName: "Franklin"}
   ]
  }
]

我在ng-repeat中使用什么表达式来按每个记录的第一个lastName排序(例如names [0] .lastName)?

1 个答案:

答案 0 :(得分:0)

使用:

ng-repeat="e in entries | orderBy:'names[0].lastName'"

或:

ng-repeat="e in entries | orderBy:'-names[0].lastName'"

用于逆序。