组件加载时发送接口请求获取数据,在根据收集到的数据的某一项值在进行请求获取相对应的值,实现联动效果
1 useEffect(() => { 2 // getQuestionDetail({ id: '61a78f53245afb73590f4642aab4b3e1' }).then((res) => { 3 getQuestionDetail({ id: rowData.id }).then(async (res) => { 4 console.log('res', res); 5 const { 6 questionInfoMain: { content, questionDes, questionDetaildes, questionContent }, 7 } = res.data; 8 questionForm.setFieldsValue({ questionDes, questionDetaildes, questionContent }); 9 console.log('content', JSON.parse(content)); 10 11 setCompts(JSON.parse(content)); 12 getCompsData(JSON.parse(content)); 13 var template = JSON.parse(content); 14 template.map((i) => { 15 const { 16 properties: { value }, 17 _id, 18 } = i; 19 let o = {}; 20 let id = _id; 21 o[id] = value; 22 questionForm.setFieldsValue(o); 23 24 return i; 25 }); 26 27 let temp = JSON.parse(content); 28 await Promise.all( 29 _.map(temp, async (obj, index) => { 30 if (obj.type === 5) { 31 const codeRes = await getDicData(obj.properties.dic_code); 32 let item = codeRes.data?.filter((el) => el.code === obj.properties.value); 33 if (item) obj.properties.textValue = item[0]?.enumValues; 34 else { 35 obj.properties.textValue = obj.properties.value; 36 } 37 } else { 38 obj.properties.textValue = obj.properties.value || ''; 39 } 40 41 return obj; 42 }) 43 ); 44 console.log('temp', temp); 45 setCompts(temp); 46 setTextContent(temp); 47 }); 48 }, []);
标签:异步,obj,temp,初始化,res,id,react,content,properties From: https://www.cnblogs.com/zihang-cheng/p/16625815.html