创建一个promise对象
目录
前言
我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷
导语
歌谣 歌谣 有什么好的方式在react中将数据传给父组件

编辑
代码部分
``` return new Promise((resolve, reject) => { this.props.form.validateFieldsAndScroll((error, values) => { if (error) { reject(); return; }
const { activeUpdateData = {}, type } = this.props;
const { birthdayTime } = values;
const { imgUrl, listCards, activeOrgan, tags, tagList,
tagListInfo } = this.state;
if (!imgUrl && !activeUpdateData.headImg) {
message.info(`请上传讲师头像!`);
reject();
return;
}
console.log(values, 'values');
var arr2 = [];
console.log(tagList, 'tagListTest');
tagList.map((item) => {
if (item.checked == true) {
arr2.push({
tagCode: item.tagCode,
weight: item.weight ||
(tagListInfo && tagListInfo[0] .weight), tagGroupCode: item.tagGroupCode || (tagListInfo && tagListInfo[0].tagGroupCode), tagBizType: item.tagBizType || (tagListInfo && tagListInfo[0].tagBizType), }); } return arr2; }); if (arr2.length == 0) { this.setState({ errType: 'error', errMsg: '请选择主营课程', }); return false; } const payload = { ...values, lecturerOrganizationCode: values.lecturerOrganizationCode[0]. code, invitePeople: values.invitePeople[0].customerCode, applyCustomerCode: values.applyCustomerCode[0].customerCode, lecturerId: activeUpdateData.lecturerId, certificateId: activeUpdateData.certificateId, contactId: activeUpdateData.contactId, birthdayTime: birthdayTime && birthdayTime.valueOf(), headImg: imgUrl || activeUpdateData.headImg, businessMerchantCode: values.lecturerOrganizationCode[0].businessMerchantCode || activeUpdateData.businessMerchantCode, // activeOrgan.businessMerchantCode || activeUpdateData.businessMerchantCode, //经营商户编号 platformMerchantCode: values.lecturerOrganizationCode[0].platformMerchantCode || activeUpdateData.businessMerchantCode, // activeOrgan.platformMerchantCode || activeUpdateData.businessMerchantCode, //平台商户编号 // lecturerOrganizationCode: activeOrgan.code || activeUpdateData.lecturerOrganizationCode,
certificateList: listCards.map((item) => {
return {
certificateImgPath: item.imageUrl,
certificateImgType: item.key,
};
}),
// tagList &&
tagBizList: arr2,
// lecturerDetails: text,
};
if (type === 'update') {
payload.lecturerDetails = activeUpdateData.lecturerDetails;
payload.lecturerId = activeUpdateData.lecturerId;
payload.organizationId = activeUpdateData.organizationId;
}
console.log(payload, 'payload');
resolve(payload);
});
});
}; ```
总结
利用promise的正确返回值作为结果返回给父组件使用

浙公网安备 33010602011771号