如何在下拉选择标签中选择值,请帮助实现如下。
这是我的代码
<div>
<SelectField
label={"Select Job Category"}
onChange={(e) => {
console.log(e.target);
}}
value={listJobCategories}
data={listJobCategories?.map((v) => (
<option
key={v.id}
value={v}
onChange={(e) => {
console.log(v);
console.log(e);
}}
>
{v?.attributes?.Name}
</option>
))}
/>
{listCategories && (
<div className="flex flex-row flex-1 space-x-2 mt-4 mb-6">
{listCategories?.map((v) => (
<Badge
title={v?.id}
className="text-white p-2"
key={v?.id}
isDeleteOn={true}
onClickDelete={() => {
console.log(v?.id);
// setListCategoriesId((prev) =>
// prev.filter((el) => el != v?.id)
// );
// setListCategories((prev) =>
// prev.filter(
// (el) => el?.attributes?.Name != v?.attributes?.Name
// )
// );
}}
/>
))}
</div>
listJobCategories是api中的useState,数据结构如下所示:
{
"id": 2,
"attributes": {
"Name": "Accounting & Finance",
"createdAt": "2022-09-08T04:40:53.307Z",
"updatedAt": "2022-11-21T14:48:49.994Z",
"publishedAt": "2022-09-08T04:40:54.154Z",
"Type": null
}
},
{
"id": 3,
"attributes": {
"Name": "Corporate Affairs & Legal",
"createdAt": "2022-09-08T04:41:25.968Z",
"updatedAt": "2022-11-21T14:51:53.205Z",
"publishedAt": "2022-09-08T04:41:26.822Z",
"Type": null
}
}
}
这是UI的外观
我期望达到如下目标
I have console log e.target, result as below
2条答案
按热度按时间djmepvbi1#
您可以使用
e?.currentTarget.value
访问包含所选值的选择值!rseugnpd2#
碱性溶液
希望这对你有所帮助,如果你想要确切的解决方案,请创建一些最小的可复制的例子