.filter()的使用:方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
语法:
const arr= [32, 33, 16, 40];
const arr1 = arr.filter(item => item >= 18)
console.log(arr) // [32, 33, 16, 40]
console.log(arr1) // [32, 33, 40]
map()的使用:方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值;
map() 方法按照原始数组元素顺序依次处理元素。
语法:
const arr= [4, 9, 16, 25];
const arr1 = arr.map(item => item+2)
console.log(arr) // [4, 9, 16, 25]
console.log(arr1) // [6, 11, 18, 27]
------------------------------map()方法的具体使用-------------------------
修改
删除
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.projectId);
this.projectNameIds = selection.map(item => item.projectName); //map的使用
this.single = selection.length!=1
this.multiple = !selection.length
},
------------------------------filter()方法的具体使用-------------------------
后台数据
//表格数据-获取部门项目信息
projectList(){
this.loading = true;
listProject(this.queryParams).then(response=>{
// console.log(response.rows)
this.projectRoleList = response.rows.filter(v => v.delFlag !== 2); //filter的使用
//-----delFlag=2隐藏删除整行---------
response.total = this.projectRoleList.length;
this.total = response.total;
this.loading = false;
});
},