[英]How do I use valueComponent prop to render the selected Item if I am using optionsRenderer in react-select
Say I have my react-select component with the following props. 说我有带有以下道具的react-select组件。 I am using pug syntax. 我正在使用哈巴狗语法。
What works 什么有效 My dropdown displays every option correctly with all options custom rendered using the optionsRenderer
prop... 我的下拉菜单正确显示了每个选项,并使用optionsRenderer
自定义呈现了所有选项。
However the results I get are that the input value is just a text I have referenced in my option.label
field. 但是我得到的结果是输入值只是我在option.label
字段中引用的文本。 In the first option, Custom
is my label key. 在第一个选项中,“ Custom
是我的标签键。
use the valueComponent
to display exactly what the same HTML that options renderer is displaying inside the options dropdown. 使用valueComponent
来显示选项下拉菜单中显示的与选项渲染器完全相同的HTML。
Like this, styling can be improved of course :) 这样,样式当然可以改善:)
... ...
const customOption = (option) => pug`
div
strong #{option.label}
p #{option.renderMethod}
div
strong $#{option.otherHTMLData}
`
The function below is expected by the optionRenderer
props and iterates on the options supplied. 下面的功能由optionRenderer
期望,并在提供的选项上进行迭代。
const customOption = (option) => pug` div strong #{option.label} p #{option.renderMethod} div strong $#{option.otherHTMLData} `
But valueComponent
only expects 1 static component. 但是valueComponent
只需要1个静态组件。 Therefore any function like () => <span>Will show this</span>
因此,任何类似() => <span>Will show this</span>
函数() => <span>Will show this</span>
How do I get the option that is selected to be used as the input value using valueComponent
? 如何使用valueComponent
获得选择用作输入值的选项?
The label displayed by the ValueContainer
depends on isMutli
. ValueContainer
显示的标签取决于isMutli
。 If isMulti
is false, you control this display by overriding the SingleValue
component. 如果isMulti
为false,则可以通过覆盖SingleValue
组件来控制此显示。 If isMulti
is true, you control this display by overriding the MultiValue
component (more specifically, it's MultiValueLabel
component). 如果isMulti
为true,则可以通过重写MultiValue
组件(更具体地说,它是MultiValueLabel
组件)来控制此显示。
See the Components documentation for some simple examples. 有关一些简单示例,请参见组件文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.