新增方法:
addFloor() {
this.floors.push({
title: '标题',
comps: [],
guid: Date.now(),
});
},
提交后台方法:
saveEdit() {
const compIds = [];
this.floors.forEach((floor) => {
floor.comps.forEach((comp) => {
compIds.push(comp.id);
this.title = floor.title;
});
});
createRowData([{ title: this.title, compAryIds: compIds }]).then((res) => {
this.floors = res;
console.log(this.floors);
this.$message.success('保存成功');
});
},
但是保存后不论添加多少行,所有数据页面都显示在第一行:
而我想要的是这样:[{第一行},{第二行}]
我错在哪里,大佬
不知道我有没有理解你的描述。
试试看下面这句:
const compAryIds = this.floors.map(floor => floor.comps.map(comp=> item.id))