涉及的情况
这种情况 是确保添加的数据和 原数组中结构是
data:{
item:[{
mag:[{},{},....],
title:''
},
{
mag:[{},{},....],
title:''
},.......]
}
data:[{},{}]
- 1.借助子组件传值 情况 (弹框是子组件 点击确定 传到 父组件里面)
1.保存 点击按钮
<el-button type="primary" @click="save">确 定</el-button>
方法 methods
save() {
this.$emit('tableList', this.list_main)
this.close()
},
2.在父组件中引入
import SelectContentEdit from './components/selectContentEdit'
<SelectContentEdit
ref="SelectContentEdit"
:items="form.titleItems"
@tableList="tableList"
></SelectContentEdit>
方法 methods
tableList(data) {
this.listLoading = true
console.log(this.flagCount, 'res', data)
if (this.flagCount.length) {
for (let i = 0; i < this.flagCount.length; i++) {
let arr = data.find((item) => {
return item.questionId === this.flagCount[i]
})
if (arr) {
this.$baseMessage('已存在,请重新选择', 'error')
return
}
}
}
this.form.titleItems.map((item, index) => {
if (index == this.indexCount) {
this.form.titleItems[this.indexCount].paperQuestionList.push(
...data
)
let arr = this.form.titleItems[this.indexCount].paperQuestionList
let newobj = {}
this.form.titleItems[this.indexCount].paperQuestionList =
arr.reduce((preVal, curVal) => {
newobj[curVal.questionId]
? ''
: (newobj[curVal.questionId] = preVal.push(curVal))
return preVal
}, [])
this.form.titleItems[this.indexCount].paperQuestionList.forEach(
(item, index) => {
Object.assign(item, { questionId: item.questionId })
}
)
}
})
let ids = data.map((item) => item.questionId)
this.flagCount = [...this.flagCount, ...ids]
this.getTotalSore()
setTimeout(() => {
this.listLoading = false
}, 300)
},
待更新。。。
|