导语
歌谣 歌谣 有什么好的方式在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的正确返回值作为结果返回给父组件使用