小编Sak*_*shi的帖子

如何根据 ID 从打字稿中的记录中删除条目

我有一个 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)

frontend typescript reactjs

10
推荐指数
2
解决办法
2万
查看次数

如何根据键从 Typescript 中的字典数据结构中删除条目?

我正在使用字典数据结构,其中键是 Id,值是 PersonInformation,

interface PersonInformation{
FirstName:string;
SecondName:string;
Age:string;
}
Run Code Online (Sandbox Code Playgroud)

如何根据 ID 从词典中删除某个人的条目。

dictionary typescript reactjs

7
推荐指数
1
解决办法
8242
查看次数

标签 统计

reactjs ×2

typescript ×2

dictionary ×1

frontend ×1