【问题标题】:Error with dynamically mapped radio group动态映射的无线电组出错
【发布时间】:2022-01-13 04:00:40
【问题描述】:

我正在尝试从 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"
            }
          ]
}

我希望这是有道理的。我很高兴澄清任何事情。提前致谢。

【问题讨论】:

    标签: javascript html reactjs react-native radio-group


    【解决方案1】:

    用反应片段(&lt;Fragment&gt; &lt;/Fragment&gt;)或空(&lt;&gt;&lt;/&gt;)标签包装您的输入

     {candidateData.map((candidate) => (
         <>
            <input type="radio" value={candidate.name} name={candidate.name}/> 
            This is where I want to add the label 
         </>
      ))}
          
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-09
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多