宜搭如何实现关联项多选填充子表单时,修改了某行,再次添加多选项时,修改的数据行不被重置
附上最后成功实现的代码:
const currentData = this.$('tableField_liyfl2t2').getValue();
const batchFetchLoading = this.utils.toast({
title: `处理中,请不要关闭浏览器,预计需要 ${Math.ceil(value.length / 5)} 秒`,
type: 'loading'
});
try {
const batchFetchResult = await Promise.all(
value.map(async (form) => {
const res = await this.dataSourceMap.getDataById.load({
formInstId: form.instanceId
});
return res || {};
})
);
batchFetchLoading();
const newData = batchFetchResult.map((item) => {
const { formData = {} } = item;
const existingData = currentData.find((data) => data && data._id === item.formInstId);
if (existingData) {
// 数据项已存在,不填充任何字段
return existingData;
} else {
// 数据项不存在,创建新行并填充所有字段
return {
_id: item.formInstId,
textField_liyfl2t6: formData.textField_lhyfrduh || '',
textField_liyfl2t3: formData.textField_lha93y6t || '',
textField_liyfl2t4: formData.textField_lha93y6u || '',
textField_liyfl2t5: formData.textField_lha93y6v || '',
numberField_liyfl2ta: formData.numberField_lha93y6y || 0,
numberField_liyfl2tb: (formData.numberField_lhabu22e || 0) * (formData.numberField_lha93y6y || 0),
numberField_liyfl2td: formData.numberField_lhbsvhio || 0,
numberField_liyfl2tc: (formData.numberField_lhbsvhio || 0) * (formData.numberField_lhabu22e || 0),
numberField_liyfl2t9: formData.numberField_lhabu22e || 0,
numberField_lj3luf14: formData.numberField_lhabu22e || 0,
textField_liyfl2t7: formData.textField_lgq6n9dz || '',
textField_liyibdac: formData.textField_lha93y6w || ''
};
}
});
this.$('tableField_liyfl2t2').setValue(newData);
} catch (error) {
batchFetchLoading();
this.utils.dialog({
method: 'alert',
title: '处理出错',
content: '请求关联数据失败。',
onOk: () => { },
onCancel: () => { }
});
}
}
赞0
踩0