Javascript 如何在Reactjs中从json服务器删除数据
JSON数据的链接Javascript 如何在Reactjs中从json服务器删除数据,javascript,reactjs,axios,localhost,json-server,Javascript,Reactjs,Axios,Localhost,Json Server,JSON数据的链接 如何从JSON数据中删除subjectname 我的密码在这里 http://localhost:3003/CourseList 是我的本地JSON服务器 const deleteSub = async id => { try{ const data = await axios.get("http://localhost:3003/CourseList") //How should I map
如何从JSON数据中删除subjectname 我的密码在这里 http://localhost:3003/CourseList 是我的本地JSON服务器
const deleteSub = async id => {
try{
const data = await axios.get("http://localhost:3003/CourseList")
//How should I map and delete the subname ????
}
catch(err){
console.log(err.message)
}
};
可以使用.filter方法执行此操作
const deleteSub = async id => {
try{
const data = await axios.get("http://localhost:3003/CourseList")
const filteredData = data.filter(d => d.id !== id)
console.log(filteredData)
}
catch(err){
console.log(err.message)
}
};
您是否尝试过使用
.forEach
循环json并使用delete
关键字删除所需的密钥?什么json?请在问题中包含所有相关代码,确保它是一个?嗨,OP的问题似乎是删除一个特定的键,而不是过滤整个对象。