我的useState可以使用我的id代替我的数组索引吗?错误表示未定义

问题描述

还是新来的。我正在做一个决策树,我想用我的id而不是我的数组索引来根据用户的回答在响应数组中跳转,但是我不确定该怎么做。它不断告诉我ID是未定义的。 PS并不是所有的阵列都在这里

  const responses = [
    
    {
      id: question_1,questionText: "Is the account data entry?",answerOptions: [
        { answerText: "No",isCorrect: false },{ answerText: "Yes",isCorrect: true,jumpToQuestion: question_3 },],notes: [
      ],},{
      id: question_2,questionText: "Is this customer 1 or 2?",isCorrect: true},{
      id: question_3,questionText: "Is the caller",answerOptions: [
        { answerText: "Power of Attorney/Conservator",jumpToQuestion: question_15 },{ answerText: "Lawyer",jumpToQuestion: question_13 },{ answerText: "Emergency Responder",jumpToQuestion: question_14 },{ answerText: "Wanting to make a payment",{ answerText: "None",const [currentQuestion,setCurrentQuestion] = useState(question_1);

  const handleAnswerButton = (jumpToQuestion) => {
    const nextQuestion = jumpToQuestion || currentQuestion + 1;
    setCurrentQuestion(nextQuestion);
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)