Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用.map函数在react中显示问卷答案的状态_Javascript_Reactjs - Fatal编程技术网

Javascript 使用.map函数在react中显示问卷答案的状态

Javascript 使用.map函数在react中显示问卷答案的状态,javascript,reactjs,Javascript,Reactjs,我已经在这个问题上纠缠了很长一段时间了,任何建议在这里都会有很大帮助 我有一个页面,它创建了一个对象数组,当控制台被记录时,如下所示 0: {answer: "yes", question: "Is the keyboard set to a suitable height", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 30, …} 1: {answer: "yes", question: "Is it

我已经在这个问题上纠缠了很长一段时间了,任何建议在这里都会有很大帮助

我有一个页面,它创建了一个对象数组,当控制台被记录时,如下所示

0: {answer: "yes", question: "Is the keyboard set to a suitable height", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 30, …}
1: {answer: "yes", question: "Is it possible to find a comfortable typing postion?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 31, …}
2: {answer: "yes", question: "Do you have a good keyboard technique?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 32, …}
3: {answer: "yes", question: "Are the characters on the keyboard clear and readable?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 33, …}
4: {answer: "yes", question: "Is your mouse or other pointing device suitable to the task you're using it for?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 34, …}
5: {answer: "yes", question: "Is the mouse (or other pointing device) located sufficently close to you?  ", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 35, …}
6: {answer: "yes", question: "Is there support for your wrist and forearm when using the mouse(or other pointing device)", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 36, …}
7: {answer: "yes", question: "Does the mouse (or other pointing device) work smoothly at a speed that suits you?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 37, …}
8: {answer: "yes", question: "Can you easily adjust the software settings for speed and accuracy of the pointer?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 38, …}
9: {answer: "yes", question: "Are the characters on your screen clear and readable?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 39, …}
10: {answer: "yes", question: "Is the text size on your screen confortable to read?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 40, …}
11: {answer: "yes", question: "Is the image on your screen free from flicker and jitter?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 41, …}
12: {answer: "yes", question: "Is your screen's specification suitable for its intended use?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 42, …}
13: {answer: "yes", question: "Is the brightness and/or contrast on your screen adjustable?", state: "Accepted", email: "henryjohnpeters@gmail.com", questionId: 43, …}
length: 14
展开时,每个对象看起来都会根据响应而变化。(忽略状态属性,此属性将被删除。)

此数组称为结果

当问卷提交时,我有一个onclick函数,如下所示

submitAnswers() {
    let completeToken = "";
    if (questionCounter == this.state.questions.length) {
      var today = new Date(),
        date = `${today.getUTCFullYear()}-${today.getUTCMonth() +
          1}-${today.getUTCDate()} ${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}.${today.getMilliseconds()} `;

      if (results.find(q => q.Accepted == 1)) {
        completeToken = "Not Complete";
      }
      console.log(completeToken);

      const data = {
        results,
        date
      };

      fetch("/post-question-answers/", {
        method: "POST", // or 'PUT'
        headers: {
          Accept: "application/json,",
          "Content-Type": "application/json"
        },
        body: JSON.stringify(data)
      }).then(response => {
        console.log("response before it is broken down " + response);

        return response.json();
      });

      // window.location.href = "http://localhost:3000/completed-assessment";
    } else {
      alert("Please enter all of The questions");
    }
  }
这里的问题是我正在努力做到这一点

if (results.find(q => q.accepted == 1)) {
        completeToken = "Complete";
      }
      console.log(completeToken);
它正在这些对象中搜索.accepted=1,这意味着它是一个可接受的问题。但是,my console.log根本不显示任何内容


如果可以的话,请帮助我一整天都在努力解决这个问题

看起来像是一个打字错误q.Accepted(大写字母a),在对象描述中它被称为“Accepted”,因此undefined==1,它总是false,在控制台日志中completedToken值是“”(空字符串)因此,结果中没有可见的内容。

可能所有问题都没有被接受……从您的代码中也不清楚
结果
变量是如何产生的。你不会做任何类似
constresults=this.state.results
submitAnswers代码中的results.find块与下面的代码段不匹配,它使用了“q.Accepted”而不是“q.Accepted”。这是一个输入错误吗?很抱歉,这是一个输入错误,这不是我在代码中如何输入的问题。在代码中,我是这样做的,但它不起作用。请确保结果数组中至少有一个对象接受值1,我已尝试过,它正在打印completedToken值,如果仍然有问题,请在react游乐场上分享演示片段。
if (results.find(q => q.accepted == 1)) {
        completeToken = "Complete";
      }
      console.log(completeToken);