Ich möchte ein bedingtes Rendering in einer Map erstellen. Die Daten werden aus einer JSON-Datei mit dieser Struktur wurde: Export const Produkte = [Bedingte interne Karte 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."
}
]
}
]
So habe ich eine Karte durch das Feld und dann möchte ich den Inhalt Abschnitt machen je nachdem, was ist der Typ. Früher habe ich eine doppelte Karte für dieses und ich brauche eine bedingte in der zweiten Karte, aber es funktioniert nicht:
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>
})}
Danke. Eines der Elemente der JSON-Datei ist ein HTML-Abschnitt, der als String gespeichert wird. Wie kann ich es als HTML auf der Seite rendern? – ocram
Überprüfen Sie die aktualisierte Antwort :) –