简体   繁体   English

基于id的react-select resolve选项

[英]react-select resolve option based on id

For select2 library, there was an option called initSelection which would enable users to resolve the label based on the selected value. 对于select2库,有一个名为initSelection的选项,该选项使用户可以根据所选值解析标签。

Is there something similar for react-select ? 是否有类似的反应选择?

The onChange prop of the react-select gets called with the selected option. react-select的onChange属性将与selected选项一起调用。 Which is an object and has the label and the value of the selection, just like in example of the component. 就像组件示例一样,它是一个对象,具有标签和所选内容的值。

https://github.com/JedWatson/react-select#usage https://github.com/JedWatson/react-select#usage

Save the label to state and use it where you like. 保存标签以注明状态并在需要的地方使用它。 The example logs the selected option's label to console. 该示例将所选选项的标签记录到控制台。 Check it out. 看看这个。

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

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