this.props.datacat.map(singleData=>{
return Object.keys(singleData).map((key,i) =>{
if(key==='name'){
return <OptGroup label = {singleData[key]}>
}else{
return <Option key= {key} >{singleData[key]}</Option>
}
return </OptGroup>
})
})
(this.props.datacat) 的数据
[
{
"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"
}
]
上面的代码如果键是名称则尝试显示数据,然后创建optgroup标签,否则它将显示选项值中的所有数据。之后,应该在选项值内的选项值 id<Option key= {key} >{singleData[key]}</Option>
和要显示的文本就是该值。有人知道怎么做吗 :( ?