我正在嘗試從 JSON 檔案動態映射無線電組。我已經弄清楚了,但問題是我似乎無法在不出錯的情況下為每個收音機添加標簽。錯誤是“)預期的”。我認為這是因為 div 標簽在映射之外,但我不確定。這是無線電組的代碼
<div onChange={this.onChangeValue}>
{candidateData.map((candidate) => (
<input type="radio" value={candidate.name} name={candidate.name}/> This is where I want to add the label that throws an error
))}
</div>
這是JSON
{
"candidates":[
{
"name":"Uncle Ruckus",
"politics":"R-District 21",
"img":"./Candidates/uncleruckus.jpg"
},
{
"name":"Uncle Ruckus",
"politics":"R-District 21",
"img":"./Candidates/uncleruckus.jpg"
}
]
}
我希望這是有道理的。我很高興澄清任何事情。提前致謝。
uj5u.com熱心網友回復:
用反應片段(<Fragment> </Fragment>)或空(<></>)標簽包裝您的輸入
{candidateData.map((candidate) => (
<>
<input type="radio" value={candidate.name} name={candidate.name}/>
This is where I want to add the label
</>
))}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409525.html
標籤:
下一篇:字串陣列到樹資料結構?
