我有一个 Main.tsx 文件,其中有一个记录,personList,键为 PersonId,值为 PersonInfo,我想根据提供的 Id 从 personList 中删除特定条目。下面是我的代码:
interface PersonInfo{
FirstName:string;
SecondName:string;
Age:string;
}
const [personList,setPersonList] = useState<Record<string,PersonInfo>>({});
//For inserting entry
const Create = () => {
setPersonList((oldList)=>{
return {
...oldList,[PersonId]:PersonDescription //PersonDescription is of type PersonInfo
}
});
};
const Delete = () => {
const newPersonList :Record<string,PersonInfo>=
personList.filter()//Here i want to delete the entry based on personId
setPersonList(newPersonList);
};
Run Code Online (Sandbox Code Playgroud) 我正在使用字典数据结构,其中键是 Id,值是 PersonInformation,
interface PersonInformation{
FirstName:string;
SecondName:string;
Age:string;
}
Run Code Online (Sandbox Code Playgroud)
如何根据 ID 从词典中删除某个人的条目。