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>應該的內部期權價值和文字顯示的是價值。有人知道怎么做嗎 :( ?
ReactJs 在 optgroup 中顯示數據
烙印99
2021-12-12 15:35:25