javascript - 如何在 React Native 中的单选按钮中提供 fetch api?

标签 javascript reactjs react-native radio-button jsx

我正在使用 this package for radio button 。我试图在单选按钮中显示 api 的结果。api 响应包含 4 个选项。所以我想用 4 个单选按钮渲染文本,但现在我只得到一个带有文本的单选按钮。这就是它的样子

enter image description here

这是代码

{
  this.state.data.map(a => (
    <Card>
      <CardItem>
        <Text style={styl.textStyle}>
          {(a.content = a.content.replace(/(<([^>]+)>)/gi, ""))}
        </Text>
      </CardItem>
      <CardItem>
        <RadioGroup
          size={24}
          thickness={2}
          color="#9575b2"
          highlightColor="#ccc8b9"
          selectedIndex={1}
          onSelect={item => this._onSelect(item, i++)}
        >
          <RadioButton value={a.options}>
            <Text>{a.options}</Text>
          </RadioButton>
        </RadioGroup>
      </CardItem>
    </Card>
  ));
}

json 响应

{
                "type": "single",
                "hint": "",
                "explanation": ".",
                "content": "<p>3. The World Banks’ Doing Business Report 2018 was the fifteenth edition since its inception in 2003. Examine the following statements about the Report and select the correct answer using the codes given below.</p>\n<p>I. Doing Business uses 11 indicator sets to measure aspects of business regulation that matter for entrepreneurship.</p>\n<p>II. India is one of the 10 economies that improved the most in the areas measured by Doing Business as per the 2018 Report.</p>\n<p>III. South Asia is the only region not represented in the top 50 ranking for ease of doing business.</p>\n",
                "options": [
                    "(a) I, II and III are correct ",
                    "(b) Only I is correct ",
                    "(c) Only I and II are correct ",
                    "(d) Only III is correct "
                ],
                "correct": "1",
                "marks": 4,
                "user_marks": 0,
                "status": 0,
                "marked": null,
                "auto": 1
            },

请帮忙。非常感谢任何帮助,谢谢。

最佳答案

您可以执行类似的操作,在 radiogroup 内进行循环,以根据 json 响应呈现单选按钮。

<RadioGroup
  size={24}
  thickness={2}
  color="#9575b2"
  highlightColor="#ccc8b9"
  selectedIndex={1}
  onSelect={item => this._onSelect(item, i++)}
  >
  {
    a.options.map((item, key) =>
    (
      <RadioButton value={item}>
        <Text>{item}</Text>
      </RadioButton>
    ))
  }
</RadioGroup>

关于javascript - 如何在 React Native 中的单选按钮中提供 fetch api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53849545/

相关文章:

javascript - 设置步数间隔 - 每步应该更长

javascript - ASP.Net 中的是/否消息框

javascript - Jquery 代码无法在网站上运行,但可以在 fiddle 中运行

javascript - React JSDOM - 如何访问元素的宽度

ios - react native 错误 : Redefinition of RCTMethodInfo after installing the plugin

react-native - React Native this .'function' is not a function

node.js - 不能在模块 Electron React Typescript 之外使用 import 语句

javascript - React Collapse - 如何切换列表中的项目?

javascript - react +火力地堡 : How to add item to list data into firebase realtime database

javascript - 当您不知道内容的大小时,如何在 react native 中为高度设置动画?