Reactjs 无法查看输出中的值
我一直在试图弄清楚为什么这在输出中不可见,很可能与react的异步性质有关,这很好。但是你需要做什么来显示内容呢 “说明”列为空 有一个包含主数据的usertable:Reactjs 无法查看输出中的值,reactjs,react-functional-component,Reactjs,React Functional Component,我一直在试图弄清楚为什么这在输出中不可见,很可能与react的异步性质有关,这很好。但是你需要做什么来显示内容呢 “说明”列为空 有一个包含主数据的usertable: {usrData.map((prop, key) => { return ( <tr key={key}> <td className="text-center">{prop.id}</td> {/*
{usrData.map((prop, key) => {
return (
<tr key={key}>
<td className="text-center">{prop.id}</td>
{/* Returns Data */}
<td className="text-left">
{
selectTimeOptions.filter(
dealer => dealer.value === prop.time_slot
)[0].label
}
</td>
{/* To double check data is present */}
<td>{prop.customergarage}</td>
<td>
{/* Does not return or show data */}
{/* But data visible in console */}
{[...prop.customergarage].forEach(d => {
if (parseInt(d, 10) > 0) {
const retrs = sTypes.filter(st => st.value === d)[0];
console.log(retrs);
return retrs;
}
})}
</td>
<td className="text-right" />
</tr>
);
})}
{usrData.map((道具,钥匙)=>{
返回(
{prop.id}
{/*返回数据*/}
{
选择TimeOptions.filter(
经销商=>dealer.value===prop.time\u槽
)[0]。标签
}
{/*重复检查数据是否存在*/}
{prop.customergarage}
{/*不返回或显示数据*/}
{/*但数据在控制台中可见*/}
{[…prop.customergarage].forEach(d=>{
如果(parseInt(d,10)>0){
常量retrs=sTypes.filter(st=>st.value==d)[0];
控制台日志(RETR);
返回RETR;
}
})}
);
})}
有任何解释和/或修正吗?特别是如何在此处使用React.useffect()?我不知道您想在此处使用useffect做什么,但我将尝试解释为什么它不渲染 首先,forEach不是这样工作的,所以您不能从中返回 其次,您可以使用构建内部部件的函数来解决所有问题
buildCustomerData = (customergarage) => {
const good = [];
customergarage.forEach(d => {
if (parseInt(d, 10) > 0) {
const retrs = sTypes.filter(st => st.value === d)[0];
console.log(retrs);
good.push(retrs)
}
})
return good;
}
{usrData.map((prop, key) => {
return (
<tr key={key}>
<td className="text-center">{prop.id}</td>
{/* Returns Data */}
<td className="text-left">
{
selectTimeOptions.filter(
dealer => dealer.value === prop.time_slot
)[0].label
}
</td>
{/* To double check data is present */}
<td>{prop.customergarage}</td>
<td>
{/* Does not return or show data */}
{/* But data visible in console */}
{buildCustomerData(prop.customergarage)}
</td>
<td className="text-right" />
</tr>
);
})}
buildCustomerData=(customergarage)=>{
常数良好=[];
customergarage.forEach(d=>{
如果(parseInt(d,10)>0){
常量retrs=sTypes.filter(st=>st.value==d)[0];
控制台日志(RETR);
好的,推(RETR)
}
})
归还货物;
}
{usrData.map((prop,key)=>{
返回(
{prop.id}
{/*返回数据*/}
{
选择TimeOptions.filter(
经销商=>dealer.value===prop.time\u槽
)[0]。标签
}
{/*重复检查数据是否存在*/}
{prop.customergarage}
{/*不返回或显示数据*/}
{/*但数据在控制台中可见*/}
{buildCustomerData(prop.customergarage)}
);
})}
仅仅是一个映射无法在内部循环中完成工作,因为在某些情况下,您的条件将无法得到满足