在地图功能中使用 handleClick 地图时,如何将删除ID发布到API服务器?
在我可以处理联接表记录的情况下,假设我想从子表中删除一条记录,我该如何处理这种情况。
<tbody>
{allRecords.map(record => (
record.posts.map(post => (
<AllRows
key={record.id}
record={record}
post = {post}
onDelete={this.handleDelete}
/>
))
))}
</tbody>
答案 0 :(得分:0)
假设您有一个看起来像这样的数组对象
const users = [
{
name: 'Rohit',
age: 18,
id: '22123'
},
{
name: 'Rohan',
age: 28,
id: '22124'
},
{
name: 'Rahul',
age: 98,
id: '22125'
}
]
const newUser = users.map(user => {
delete user.id
return user
})
console.log(newUser)
您可以简单地从地图中的用户对象中删除对象属性
答案 1 :(得分:0)
您可以将id
传递给handleDelete()
函数。
<tbody>
{allRecords.map(record => (
record.posts.map(post => (
<AllRows
key={record.id}
record={record}
post = {post}
onClick={() => this.handleDelete(record.id)}
/>
))
))}
</tbody>