我已经在这个问题上停留了很长时间了,在这里任何建议都可以走很长一段路。
我有一个页面创建一个对象数组,当控制台登录时,对象数组如下所示。
0: {answer: "yes", question: "Is the keyboard set to a suitable height", state: "Accepted", email: "[email protected]", questionId: 30, …}
1: {answer: "yes", question: "Is it possible to find a comfortable typing postion?", state: "Accepted", email: "[email protected]", questionId: 31, …}
2: {answer: "yes", question: "Do you have a good keyboard technique?", state: "Accepted", email: "[email protected]", questionId: 32, …}
3: {answer: "yes", question: "Are the characters on the keyboard clear and readable?", state: "Accepted", email: "[email protected]", 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: "[email protected]", questionId: 34, …}
5: {answer: "yes", question: "Is the mouse (or other pointing device) located sufficently close to you? ", state: "Accepted", email: "[email protected]", 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: "[email protected]", questionId: 36, …}
7: {answer: "yes", question: "Does the mouse (or other pointing device) work smoothly at a speed that suits you?", state: "Accepted", email: "[email protected]", questionId: 37, …}
8: {answer: "yes", question: "Can you easily adjust the software settings for speed and accuracy of the pointer?", state: "Accepted", email: "[email protected]", questionId: 38, …}
9: {answer: "yes", question: "Are the characters on your screen clear and readable?", state: "Accepted", email: "[email protected]", questionId: 39, …}
10: {answer: "yes", question: "Is the text size on your screen confortable to read?", state: "Accepted", email: "[email protected]", questionId: 40, …}
11: {answer: "yes", question: "Is the image on your screen free from flicker and jitter?", state: "Accepted", email: "[email protected]", questionId: 41, …}
12: {answer: "yes", question: "Is your screen's specification suitable for its intended use?", state: "Accepted", email: "[email protected]", questionId: 42, …}
13: {answer: "yes", question: "Is the brightness and/or contrast on your screen adjustable?", state: "Accepted", email: "[email protected]", questionId: 43, …}
length: 14
展开后,每个对象看起来都像根据响应而变化。 (忽略state属性,它将被删除。)
answer: "yes"
question: "Is the keyboard set to a suitable height"
state: "Accepted"
email: "[email protected]"
questionId: 30
workStation: "skrt"
accepted: "0"
date: "2020-2-20 17:11:3.616 "
该数组称为结果。
提交问卷后,我便有了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,这意味着它是一个被接受的问题。但是,我的console.log只是不显示任何内容。
如果可以的话,请帮忙,我整天都在挣扎
最佳答案
看起来像一个错字q.Accepted(大写A),在对象描述中被称为“ accepted”,因此undefined == 1始终为false,在控制台日志中,completeToken值为“”(空字符串),因此没有结果可见。