javascript - 在调查问卷末尾推送文件(json) - Javascript
问题描述
我有一个包含问题和答案的 json,它们分别显示在 div 中。用户可以点击一个答案,我有一个 onClick 功能可以转到下一个问题
() => setQuestionIndex(() => questionIndex + 1
我希望当 json“问题”完成后,推送一个新的 json“解决方案”:
onAnswer={() => {
if (questionIndex === question.length) {
() => history.push('/forms/solutions')
} else {
() => setQuestionIndex(() => questionIndex + 1)
}
}}
当我只使用() => setQuestionIndex(() => questionIndex + 1
它时,它完美地跳到下一个问题,但条件语句不起作用,有什么猜测吗?
完整代码:
const Form = enhance(({
styles, scenario, questionIndex, setQuestionIndex
}) => {
const { questions } = scenarios[scenario];
const questionTabs = questions.map((q, i) => {
if (i === questionIndex) {
return <Tab key={i} {...css(styles.tabActive)}> {i} </Tab>
}
return <Tab key={i} {...css(styles.tab)}> {i} </Tab>
})
const questionPanels = questions.map((question, i, history) => {
return (
<TabPanel key={i}>
<Question
question={question.question}
answers={question.answers}
visualAnalogScale={question.VAS}
//onAnswer={() => setQuestionIndex(() => questionIndex + 1)}
onAnswer={() => {
if (questionIndex === question.length) {
() => history.push('/forms/solutions')
} else {
() => setQuestionIndex(() => questionIndex + 1)
}
}}
/>
</TabPanel>
);
});
解决方案
这是一个错误吗?如果是这样,这条线
if (questionIndex === question.length) {
应该:
if (questionIndex === question.length - 1) {
还有为什么一切都是函数?
推荐阅读
- qt - 从源代码构建 QT 模块
- amazon-web-services - Amazon S3 映像 CORS 问题
- javascript - firebase get child by month of birthday
- excel - 涉及指数的乘积的 Sigma
- c# - WPF-如何创建一种屏幕保护程序(带计时器)
- fancybox - Fancybox - 禁用外部点击关闭
- python - 在python中grep匹配字符串的正则表达式
- microsoft-graph-api - 在 Outlook 图形 API 的重复事件范围中获取 endDate=0001-01-01
- kubernetes - 谁可以在 Kubernetes 中创建持久卷?
- docker - 无法使用 Artifactory 插件将 Docker Image 推送到 Jenkins 管道中的 Artifactory