Javascript ReactJs在optgroup中显示数据
如果键为name则尝试显示数据的上述代码,然后创建optgroup标签,否则将在选项值中显示所有数据。之后,选项值id即Javascript ReactJs在optgroup中显示数据,javascript,reactjs,ant-design-pro,Javascript,Reactjs,Ant Design Pro,如果键为name则尝试显示数据的上述代码,然后创建optgroup标签,否则将在选项值中显示所有数据。之后,选项值id即{singleData[key]}应位于选项值内,要显示的文本就是该值。任何人都知道如何做到这一点:(?对于this.props.datacat的每个条目,创建一个OptGroup,然后用该条目的所有选项填充它,除了带有键name的选项外: [ { "4967": "Others.", "4968": "Sports & Beachwear >
{singleData[key]}
应位于选项值内,要显示的文本就是该值。任何人都知道如何做到这一点:(?对于this.props.datacat
的每个条目,创建一个OptGroup
,然后用该条目的所有选项填充它,除了带有键name
的选项外:
[
{
"4967": "Others.",
"4968": "Sports & Beachwear > Others.",
"4969": "Lingerie & Nightwear > Others.",
"4971": "Pants & Shorts > Others.",
"name": "Women Clothes"
},
{
"4798": "Supplements > Others.",
"4802": "Men's Grooming > Others.",
"4952": "Others.",
"4953": "Medical Supplies > Others.",
"4954": "Personal Pleasure > Others.",
"4955": "Personal Care > Others.",
"4956": "Pedicure & Manicure > Others.",
"6647": "Lips > Lip Tint"
"name": "Health & Beauty"
}
]
this.props.datacat.map((singleData)=>(
{Object.keys(singleData)
.filter(key=>key!==“name”)
.map(键=>(
{singleData[key]}
))}
));
[
{
"4967": "Others.",
"4968": "Sports & Beachwear > Others.",
"4969": "Lingerie & Nightwear > Others.",
"4971": "Pants & Shorts > Others.",
"name": "Women Clothes"
},
{
"4798": "Supplements > Others.",
"4802": "Men's Grooming > Others.",
"4952": "Others.",
"4953": "Medical Supplies > Others.",
"4954": "Personal Pleasure > Others.",
"4955": "Personal Care > Others.",
"4956": "Pedicure & Manicure > Others.",
"6647": "Lips > Lip Tint"
"name": "Health & Beauty"
}
]
this.props.datacat.map((singleData) => (
<OptGroup label={singleData["name"]}>
{Object.keys(singleData)
.filter(key => key !== "name")
.map(key => (
<Option key={key}>{singleData[key]}</Option>
))}
</OptGroup>
));