当前位置: 首页> 财经> 产业 > 和拓者设计吧类似的网站_百度广告位价格表_汽车软文广告_世界杯32强排名

和拓者设计吧类似的网站_百度广告位价格表_汽车软文广告_世界杯32强排名

时间:2025/8/1 15:53:58来源:https://blog.csdn.net/zgx200318/article/details/146918279 浏览次数:1次
和拓者设计吧类似的网站_百度广告位价格表_汽车软文广告_世界杯32强排名

需求背景

一个select框  现在要求可多选 并且原有一个any的选项  其他选项为输入后回车自己增加  若选择了any   则其他选项不可选择反之选择其他选项any不可选择  并且回车新增时也不可直接加入到选中数组只加入到option内  并且不可重复添加新内容

实现过程

 <Form.Item label={formatMessage({ id: 'label.alarm.SourceAddress' })} name="sourceAddress"><Selectmode="multiple"maxTagCount={3}showSearchsearchValue={inputValue}onChange={(e) => createSelectionHandler(e, 'any', sourceList, setSourceList)}placeholder={formatMessage({ id: 'select.placeholder' })}onSearch={setInputValue}onInputKeyDown={sourceHandleKeyDown}options={sourceList}getPopupContainer={(triggerNode) => triggerNode.parentElement || document.body}/></Form.Item>//js部分// 源地址列表const [sourceList, setSourceList] = useState([{ value: 'any', label: 'any', disabled: false }]);// 源地址输入框const [inputValue, setInputValue] = useState('');// 通用处理函数const createSelectionHandler = (specialValue, key, stateList, setState) => {const newList = stateList.map((item) => ({...item,disabled: specialValue.includes(key)? item.value !== key // 如果选中特殊值,禁用其他选项: specialValue.length > 0 // 如果选中普通值,禁用特殊值? item.value === key: false, // 没有选中时恢复默认}));setState(newList);};// 源地址处理键盘事件(回车)const sourceHandleKeyDown = (e) => {if (e.key === 'Enter' && inputValue.trim()) {const newValue = inputValue.trim();const lis = addAlarmForm.getFieldValue('sourceAddress');if (!lis.includes(newValue)) {if (lis.includes('any')) {setSourceList([...sourceList,{value: newValue,label: newValue,disabled: true,},]);} else {setSourceList([...sourceList,{value: newValue,label: newValue,disabled: false,},].map((item) => ({...item,disabled: item.value == 'any',})),);addAlarmForm.setFieldsValue({sourceAddress: [...lis, newValue],});}}setInputValue('');}};

关键字:和拓者设计吧类似的网站_百度广告位价格表_汽车软文广告_世界杯32强排名

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: