如何将级联下拉列表的选定值绑定到 Ant Design 中的 h1 标签?
我正在使用 Ant Design 创建一个级联下拉列表。我希望将所选值作为标签返回,以显示“您选择了 {name}”之类的内容。如何将所选值绑定到 h1 标签?这是到目前为止的代码:
const options = [
{
value: 'Person',
label: 'person',
children: [
{
value: 'amy',
label: 'Amy',
},
{
value: 'john',
label: 'John'
}
],
}
];
function onChange(value, selectedOptions) {
console.log(value, selectedOptions);
}
function filter(inputValue, path) {
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
}
class CascadingDropdown extends Component{
render(){
return(
<div>
<p>Please select a person:</p>
<div>
<Cascader
options={options}
onChange={onChange}
placeholder="Please select"
showSearch={{ filter }}
onSearch={value => console.log(value)}
/>
</div>
<h1>You selected {name}</h1> // here is where I want to print the name
</div>
);
}
}
export default CascadingDropdown;
I am using Ant Design to create a cascading dropdown. I am looking to return the selected value as a tag to display something like "You selected {name}". How can I bind the selected value to the h1 tag? Here is the code so far:
const options = [
{
value: 'Person',
label: 'person',
children: [
{
value: 'amy',
label: 'Amy',
},
{
value: 'john',
label: 'John'
}
],
}
];
function onChange(value, selectedOptions) {
console.log(value, selectedOptions);
}
function filter(inputValue, path) {
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
}
class CascadingDropdown extends Component{
render(){
return(
<div>
<p>Please select a person:</p>
<div>
<Cascader
options={options}
onChange={onChange}
placeholder="Please select"
showSearch={{ filter }}
onSearch={value => console.log(value)}
/>
</div>
<h1>You selected {name}</h1> // here is where I want to print the name
</div>
);
}
}
export default CascadingDropdown;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用可以使用状态来显示所选值,如以下代码
截图所示:
Use can use state to display the selected value as shown in the following code
Screenshot: