【发布时间】:2021-02-08 20:38:40
【问题描述】:
我想根据我在 react-select 中选择的值显示不同的文本。 handlechange 时间工作正常,我的问题是当我尝试检索 p 标签中的值以根据值显示不同的文本时
我的代码:
const timeSlots = [
{
value: 0,
label: 'what is your choice ?'
},
{
value: 1,
label: 'choice 1'
},
{
value: 2,
label: 'choice 2'
},
{
value: 3,
label: 'choice 3'
},
{
value: 4,
label: 'choice 4'
}
]
class WidgetBooking extends Component {
state ={
selectedOption: null,
}
handleChangeTime = (selectedOption) => {
this.setState({ selectedOption });
console.log(selectedOption);
}
render() {
const { selectedOption } = this.state;
return (
<>
<div className="time-slots padding-bottom-30px">
<Select
value={selectedOption}
onChange={this.handleChangeTime}
placeholder="what is your choice ?"
options={timeSlots}
/>
</div>
{selectedOption === '1' &&
<p className="d-block widget-title">756, 23 $</p>
}
{selectedOption === '2' &&
<p className="d-block widget-title">865, 23 $</p>
}
{selectedOption === '3' &&
<p className="d-block widget-title">756, 23 $</p>
}
</div>
</>
);
}
}
我想在 p 标签中显示不同的价格,如上图所示。 感谢您的帮助
【问题讨论】:
-
"我的问题是当我尝试检索我的 p 标签中的值以根据值显示不同的文本"究竟是什么问题?
-
根据select中选择的值在p标签中显示我的文字
-
当前当我在我的选择中选择一个值时,什么都不显示
标签: reactjs state react-select