我查看了堆棧,但找不到我的問(wèn)題的答案,如果它是重復(fù)的,我真的很抱歉。我有一個(gè)對(duì)象數(shù)組:export const people = [ { id: 1, name: "Thom" }, { id: 2, name: "Bob" }];我正在導(dǎo)入這個(gè)文件:import {people} from '../Person';我正在分配狀態(tài): state = { peopleData: people }我正試圖像這樣破壞這個(gè)數(shù)組,但不幸的是,我不允許這樣做:const{people} = this.state.peopleData; 我無(wú)法map對(duì)我的員工進(jìn)行功能迭代的原因是什么?{people.map(person=> (<Person key={person.id} personInfo={person}/>))}我當(dāng)然可以這樣做,但我不想這樣做,因?yàn)槿绻倚枰俚鷰状?,我總是需要編?xiě)相同的代碼this.state.peopleData......:{ this.state.peopleData.map(person=> (<Person key={person.id} personInfo={person}/>))}
銷(xiāo)毀對(duì)象數(shù)組而不為每個(gè)對(duì)象分配一個(gè)變量
一只名叫tom的貓
2022-11-03 14:55:26