angular8 - 我需要用两个条件 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);
解决方案
试试这个方法。
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);
推荐阅读
- vue.js - 为什么图像不显示在 vue 中?
- evernote - 通过 API 检索标签树
- arrays - 给定两个正整数的无序列表,最大化 A[i]*B[i] + A[i]*B[j] + A[j]*B[j], i != j
- wordpress - 想要获取父类别名称而不是子类别名称而不是帖子标题
- python - TypeError:无法解压不可迭代的函数对象
- mysql - 在 Group Concat 中显示前 X 个结果
- neo4j - Neo4j | Cypher - 给定节点 A,显示 C 类型节点 B 的路径,该节点 B 具有超过 X 个 D 类型子节点
- python-3.x - python3:找不到命令
- algorithm - 使用预初始化的静态字典进行压缩
- python-3.x - 从列表列表中制作字典列表,列表 [0] 作为键,其他列表作为值