【发布时间】:2017-10-26 00:44:50
【问题描述】:
我想在地图内创建条件渲染。数据取自具有以下结构的 JSON 文件:
export const products = [
{
"scores": {
"quality": 8,
"relevancy": {
"design": 3,
"code": 9,
"business": 5
}
},
"title": "AdCall: Bringing WebRTC to display ads",
"subtitle": "The first advertising banner with video calls",
"content": [
{
"type": "text",
"body": "AdCall is a concept for a new kind of online advertising banner. Using WebRTC, it allows for a click to call action with the aim of increasing conversions. It's built with a Node backend and deployed on Heroku."
}
]
}
]
所以我通过数组创建了一个地图,然后我想根据类型呈现内容部分。我为此使用了双映射,我需要在第二个映射中使用条件,但它不起作用:
return (
<div className="LongWork">
{products.map((product, i) => {
<div className="product-wrapper" key={i}>
<div className="subtitle"><span className="subtitle-span">{product.subtitle}</span></div>
<div className="title">{product.title}</div>
{product.content.map((content, l) => {
<div className="product-content" key={l}>
{if (content.type==="text") {
return (
<div className="productText">
{content.body}
</div>
)}
}}
</div>
})}
</div>
}
)
【问题讨论】: