我想在地圖中創建條件呈現。該數據是從JSON文件,採取這種結構: 出口常量產品= [有條件的內部映射JSX
[
{
"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>
})}
謝謝。 JSON文件的一個元素是保存爲字符串的HTML部分。我如何在頁面中將其呈現爲HTML? – ocram
檢查更新的答案:) –