【发布时间】:2020-06-23 14:57:36
【问题描述】:
我有一个简单的任务,我觉得这个问题的答案也很简单。但由于某种原因,我无法绕过它。我应该从数据库中获取问题列表并将其显示在网站上。此特定部分是是或否问题。当我从数据库中获取问题时,大多数问题已经按顺序排列,“是”然后是“否”。但是,有一个被翻转了。所以我的问题是,如何将反转的顺序翻转到正确的顺序?
老实说,我没有尝试太多,因为就像我说的那样,出于某种原因,我无法理解它。但我确实知道,在数据库中,问题有一个名为 order 的字段,其中 yes 为 0,no 为 1。所以我猜我必须以某种方式使用它。
这是我呈现问题的代码,
{state.surveyQuestions.map(question => (
<span key={question.question.id}>
<FormLabel className={classes.label} component="legend">{question.question.label}</FormLabel>
<RadioGroup value={state.consent} onChange={handleChange} style={{ height: 'auto', padding: '10px' }}>
{question.question.choices.items.map(choice => (
<FormControlLabel key={choice.order} style={{ paddingTop: '1px' }} value={choice.value} control={<Radio />} label={choice.label} />
))}
</RadioGroup>
</span>
))}
这是来自数据库的内容,
"choices": {
"items": [
{
"label": "No",
"value": "{\"value\":\"0\"}",
"dataUID": null,
"description": "No",
"order": 1,
"goto": null
},
{
"label": "Yes",
"value": "{\"value\":\"1\"}",
"dataUID": null,
"description": "Yes",
"order": 0,
"goto": null
}
]
}
【问题讨论】:
标签: reactjs graphql conditional-rendering