首页 > 解决方案 > 我需要用两个条件 angular 8 过滤一个数组

问题描述

我需要用两个条件过滤一个数组null''

items:any=[
  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 
  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name   : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }    
];

let p;

p=this.items.filter(item  => item.amount  !== ''||null);

标签: angular8

解决方案


试试这个方法。

let items: any[] = [
      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },
      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      }
    ];
    let data = items.filter(e => e.amount != "" && e.amount != null) 
    console.log(data);

推荐阅读