我正在尝试制作输入字段(onChange带有道具的方法)。当我输入特定问题 ( string) 时,我会得到答案。我设法为单个字符串做到这一点,但我想多次传递一个字符串数组而不是一个字符串。const newContent = (props) => {let questions = ''; if (props.question === "let") {questions = <p> answer here </p> } else if (props.question === "var") {questions = <p> answer here </p> } else if (props.question === "const") {questions = <p> answer here </p> }let nextQuestion = ["let", "var", "const"]; if (props.question === nextQuestion) {nextQuestion = <p> answer here </p> }}
2 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
这是你想要的?
const anwers =
{ let: '<p> answer here for let </p>'
, var: '<p> answer here for var </p>'
, const: '<p> answer here for const </p>'
}
const newContent = props => anwers[props] ? anwers[props] : 'bad value';
console.log( newContent('var'))
添加回答
举报
0/150
提交
取消