Javascript 密钥未定义-我可以';不删除
我想删除答案后的问题。我的密钥未定义。 错误: 删除400(错误请求) 呈现:Javascript 密钥未定义-我可以';不删除,javascript,reactjs,Javascript,Reactjs,我想删除答案后的问题。我的密钥未定义。 错误: 删除400(错误请求) 呈现: this.state.qBank.map( ({ question, answers, correct, id }) => ( <QuestionBox key={id} question={question} options={answers} selected={a
this.state.qBank.map(
({ question, answers, correct, id }) => (
<QuestionBox key={id} question={question} options={answers} selected={answer => this.computeAnswer(answer, correct)} />
)
)}
this.state.qBank.map(
({问题,答案,正确,id})=>(
this.computeAnswer(答案,正确)}/>
)
)}
import React,{useState}来自“React”;
const QuestionBox=({question,options,selected,key})=>{
const[answer,setAnswer]=useState(选项);
const[alreadyAnswered,setAlreadyAnswered]=使用状态(false);
返回(
{问题}
{(答案| |[]).map((文本,索引)=>(
{
如果(!已被拒绝){
setAnswer([text]);
选定(文本);
SetalReadyanSweed(真);
获取(“http:/api/Remove/”+键{
方法:“删除”,
标题:{
“内容类型”:“应用程序/json”,
“授权”:`bearer${sessionStorage.getItem(“访问令牌”)}`
},
}).然后(()=>{
}).catch(错误=>{
控制台错误(err)
})
}
}}>{text}
))}
)
}
导出默认问题框;
看起来你的帖子大部分都是代码;请添加更多详细信息。
看起来你的帖子大部分都是代码;请添加更多详细信息。
看起来你的帖子大部分都是代码;请添加更多详细信息
map中的
键
在React中有不同的用途。它用于渲染优化
不能将关键点作为道具传递
使用
this.computeAnswer(答案正确)}/>
const QuestionBox = ({ question, options, selected, id }) => {
..code
}
它不起作用,我还有未定义的。。如果网站说你的帖子大部分是代码,不要只是添加垃圾文本来填充它;这不是我们的意图,也不会在社区中传播。你可能想阅读。
import React, { useState } from 'react';
const QuestionBox = ({ question, options, selected, key }) => {
const [answer, setAnswer] = useState(options);
const [alreadyAnswered, setAlreadyAnswered] = useState(false);
return (
<div className="questionBox">
<div className="question">{question}</div>
{(answer || []).map((text, index) => (
<button disabled={alreadyAnswered} key={index} className="answerBtn" onClick={() => {
if (!alreadyAnswered) {
setAnswer([text]);
selected(text);
setAlreadyAnswered(true);
fetch("http:/api/Remove/" + key, {
method: 'DELETE',
headers: {
"Content-Type": "application/json",
"Authorization": `bearer ${sessionStorage.getItem("access_token")}`
},
}).then(() => {
}).catch(err => {
console.error(err)
})
}
}}>{text}</button>
))}
</div>
)
}
export default QuestionBox;
const QuestionBox = ({ question, options, selected, id }) => {
..code
}