简体   繁体   English

React Select标签未显示

[英]React Select label not showing

I'm using the React Select Library and when I pick a label in the select field, the value shows instead of the label. 我正在使用React选择库,当我在选择字段中选择标签时,将显示值而不是标签。 When I click the dropdown, the labels show, but when I select a label, the value shows instead of the label. 当我单击下拉列表时,将显示标签,但是当我选择标签时,将显示值而不是标签。

I'm building my field here: 我在这里建立我的领域:

payment_code: {
            label: "Payment Code", value: 'payment_code', choices: paymentCodes.map((payment_code) => {

                displayChoices.payment_code[payment_code['id']] = payment_code['name'];
                console.log(displayChoices.payment_code);
                return {
                    label: payment_code['name'], value: payment_code['id']
                }
            }), type: 'choice'
        },

The other fields work correctly but this one does not. 其他字段正常工作,但这一点不行。 I'm not a front end developer so I'm pretty stumped with this. 我不是前端开发人员,因此对此感到很困惑。 I'd add the JSX but like I said, it's working correctly for the other fields. 我将添加JSX,但是就像我说的那样,它在其他字段中正常工作。

Not sure why, but 不知道为什么,但是

return {
    label: payment_code['name'], value: payment_code['id']
}

should've been 应该是

return {
    label: payment_code['name'], value: payment_code['id'].toString()
}

For some reason, the value needs to be a string. 由于某种原因,该值必须是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM