Angular 2. How to apply orderBy?

后端 未结 4 1999
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 04:13

I have a piece of code.



        
4条回答
  •  有刺的猬
    2020-12-03 04:21

    The most recent lib that I know

    https://www.npmjs.com/package/ngx-pipes

    const numbers = [2, 1, 3];
     
    const obj = [
      {id: 4, name: 'Dave', amount: 2},
      {id: 2, name: 'Michael', amount: 2},
      {id: 3, name: 'Dan', amount: 1},
      {id: 1, name: 'John', amount: 1}
    ];
     
    const deepObj = [
      {id: 1, name: 'John', amount: 1337, deep: {prop: 4}},
      {id: 2, name: 'Michael', amount: 42, deep: {prop: 2}},
      {id: 3, name: 'Dan', amount: 1, deep: {prop: 1}},
      {id: 4, name: 'Dave', amount: 2, deep: {prop: 3}}
    ];
    
    
    

    {{ numbers | orderBy }}

    {{ numbers | orderBy: '-' }}

    {{ deepObj | orderBy: 'amount' }}

    {{ deepObj | orderBy: '-amount' }}

    {{ deepObj | orderBy: 'deep.prop' }}

    {{ deepObj | orderBy: '-deep.prop' }}

    {{ obj | orderBy: ['amount', 'id'] }}

提交回复
热议问题