office-ui-fabric - 如何在其他地方更改时重置 FluentUI 下拉选择?
问题描述
我在 reactjs office 插件中使用FluentUI 下拉菜单,并希望在用户输入完全不同的文本框时重置它。我可以获得对下拉列表的引用并调用一些重置功能吗?
这是一个简单的单选下拉菜单,例如:
return <Dropdown
placeholder={"Pick a thing"}
label={"Things"}
options={ thingOptions }
onChange={ handleSelectThing }
>
我看到了https://github.com/microsoft/fluentui/issues/5917但它似乎并不完全一样。
解决方案
我的反应还不够。归根结底,解决方案非常简单:
this.state = {
// other state,
selectedThing: undefined
}
const selectedThingKey =
thingOptions.reduce(
(acc, elt, index) => {
return acc || (this.state.selectedThing === index && elt.key)
},
false);
return <Dropdown
options={ thingOptions }
onChange={ (ev,op,i) => {
this.setState({selectedThing: i});
return handleSelectThing(ev, op, i);
}
}
selectedKey={ selectedThingKey }
notifyOnReselect={true}
/>
推荐阅读
- windows - 组策略委派中权限的访问掩码
- reactjs - 如何对数字进行表单验证
- json - OrientDB索引键值更新查询问题
- flask - 尝试在 Azure 上登录 GoogleOauth,但出现空白页
- ajax - 我想使用 ajax 监控两个文本文件
- asp.net-core - 根据 FileHelpers 示例,如何使用 GetRandomFileName 保存上传的文件以供使用?
- javascript - 无法在应用程序开发工具(javascript)中获取订单按钮的属性值
- python-3.x - 在 python3 中创建十六进制校验和的问题
- mysql - 如何解决 Laravel 6 中的 MariaDB 语法错误?
- hdfs - 调试错误 [Vertica][VJDBC](100172) 一行或多行被服务器拒绝