【问题标题】:how to sort array of objects according to sub property in ng2-order-pipe如何根据ng2-order-pipe中的子属性对对象数组进行排序
【发布时间】:2018-01-14 08:34:47
【问题描述】:

我正在处理需要对对象数组进行排序的 angular2 项目, 我在这里使用 ng2-order-pipe 对对象数组进行排序:

<p *ngFor="let customer of customers | orderBy: 'Name'">{{ customer.Name}}</p>

Name 属性是 customer 中的一个属性,排序工作正常, 但我想做的是根据 customer.Group.Name 对数组进行排序。 这是 ng2-order-pipe 的文档: https://www.npmjs.com/package/ng2-order-pipe

【问题讨论】:

  • 你试过orderBy: 'Group.Name'吗?
  • 是的,我试过了,但没有用

标签: angular


【解决方案1】:

你应该使用点运算符

<p *ngFor="let customer of customers | orderBy: 'Group.Name'">{{ customer.Name}}</p>

DEMO

【讨论】:

  • 查看上面的演示
猜你喜欢
  • 2023-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 2019-12-19
相关资源
最近更新 更多