要求:过滤出table里有数据的头部信息
data(){
return{
//table里的头部信息
header: [
{ name: '工资', colename: 'salary', strisinactive: '启用', inttype: '1' },
{ name: '日期', colename: 'date', strisinactive: '停用', inttype: '2' },
{ name: '城市', colename: 'city', strisinactive: '启用', inttype: '3' },
{ name: '职务', colename: 'job', strisinactive: '启用', inttype: '2' },
{ name: '爱好', colename: 'love', strisinactive: '停用', inttype: '3' }
],
//table里的循环数据
tableData: [
{ salary: '10000', date: '2020-07-01', love: '篮球', sex: '男' },
{ salary: '5000', date: '2020-07-02', love: '乒乓球', sex: '女' },
{ salary: '8000', date: '2020-07-05', love: '羽毛球', sex: '男' }
],
copyData: []
}
}
方法一:
getData() {
Object.keys(this.tableData[0]).map((item) => {
this.header.map(items => {
if (items.colename === item) {
this.copyData.push(items)
}
})
})
},
方法二:
getData() {
this.copyData = this.header.filter(item => this.tableData[0][item.colename] !== undefined)
},