[英]Return jsx using the map function
I am new to react-redux
. 我是
react-redux
新手。 Here what I am doing is , 我在这里做的是
return analitics.map(analiticss => (
<div className="col-md-8 d-flex justify-content-around questionDetailRow1">
<div>
<span>
<i
className="fa fa-check-circle"
style={{ fontSize: "24px", color: "green" }}
/>
</span>
<span className="ml-2">
{analitics.wrong ? `${analitics.wrong}` : "0"}
</span>
</div>
<div>
<span>
<i
class="fa fa-times-circle"
style={{ fontSize: "24px", color: "red" }}
/>
</span>
<span className="ml-2">{analiticss.wrong}</span>
</div>
<div>
<span className="skip-background">
<i className="fa fa-fast-forward" style={{ color: "black" }} />
</span>
<span className="ml-2">{analiticss.skipped}</span>
</div>
<button type="button" className="btn btn-outline-primary">
Change
</button>
</div>
));
So, here I want to have this div on any condition. 因此,在这里我想在任何情况下都具有该div。 so what happens is ,
所以发生的是
if the analiticss is not present then this will not get return. 如果不使用麻醉剂,则不会获得回报。 Because that there is no element to iterate.
因为没有要迭代的元素。
so, I want to show that values as a `0.{analiticss.skipped} this values. 因此,我想将该值显示为0。{analiticss.skipped}该值。
But it does not return this element as it does not have any array element. 但是它不返回此元素,因为它没有任何数组元素。
One solution that I have is to use if else with expplicitely adding same html in this with 0 values. 我要解决的一个办法是使用其他方式在其中明确添加具有0值的相同html。
But I don't think its a right solution. 但是我认为这不是正确的解决方案。 is there any onther solution that I can use ?
我可以使用其他解决方案吗?
If you want to still have the wrapper div visible, you need to move the map function inside of the wrapper div. 如果仍然希望包装器div可见,则需要在包装器div内移动map函数。 Something like:
就像是:
<div className="col-md-8 d-flex justify-content-around questionDetailRow1"> {analytics.map(...)} </div>
You can try this Sandbox Link. 您可以尝试此沙盒链接。
I have added your code and there is no data inside the analytics. 我已添加您的代码,并且分析中没有数据。
https://codesandbox.io/s/zwr8391y24 https://codesandbox.io/s/zwr8391y24
Still you will see the Skipped 仍然会看到跳过的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.