我在表格中有一个选择下拉菜单,当我尝试选择一个选项时,我想将整个对象发送到 onchange 函数。是否可以发送整个对象?我怎样才能做到这一点?
这就是我尝试过的。
data = [
{id:1,name:"tasha",code:"T!@#"},
{id:2,name:"dia",code:"ew34"},
{id:3,name:"alex",code:"loiu"},
{id:4,name:"rubee",code:"1234"},
]
const selectUser = (value: any, record: any) =>{
console.log("selected user details ", value); //if i select first option it will print {id:1 name:"tasha",code:"T!@#"}
console.log("table record", record);
}
const column = [
{
title: "id",
dataIndex: "id",
key: "id",
},
{
title: "user",
dataIndex: "user",
key: "user",
render: (text: any, record: any) => {
return (
<Select
style={{ width: 120 }}
onChange={(user) => selectUser(user, record)}
>
{data.map((item: any) => {
return <Option value={item}>{item.name}</Option>;
})}
</Select>
);
},
},
]
我收到以下错误
react-dom.development.js:13414 Uncaught Error: Objects are not valid as a React child (found: object with keys {id, name, code}). If you meant to render a collection of children, use an array instead.
但是如果我设置 value={item.id} ,这可以正常工作而不会出现任何错误,但是我想发送整个对象而不仅仅是 id