react-ant-design-Select多选选择器禁用选项处理&&选项数据处理
顺便提一下
发布日期:2021-05-20 10:07:12
浏览次数:40
分类:技术文章
本文共 2689 字,大约阅读时间需要 8 分钟。
1、
2、实现禁用部分选项用到的是js的some方法
subjects.map(subject => { return ( ); })
3、
顺便提一下下拉选择框的onChange事件
**change事件分两种情况**
- 一种是点击选项的X value值即是最终的取值
- 一种是下拉框中点击该项 进行选取操作 value值是被排除的值
if (isNaN(lastValue)) { initResult.length = 0; initResult = [].concat(value); } else { const initValue = ['', '', '期中成绩', '期末成绩', '综评成绩'][lastValue]; if ((initResult || []).includes(initValue)) { initResult = initResult.filter(e => e !== initValue); } else { initResult.push(initValue); } }
对于数组的操作最好是加上(initResult || []).forEach
,防止当数组不存在的时候报错。
(text || '')
(initResult || []).forEach(item => { const newValue = ['', '', '期中成绩', '期末成绩', '综评成绩']; const indexValue = newValue.findIndex(e => e === item); newCascaderData.push({ index: cellIndex, selectValue: [`${ typeId}`, `${ typeId}-${ indexValue}`], }); });
handleCascaderChange = (cellIndex, typeId, value) => { const { dispatch, archivesBookComposition: { abapList }, } = this.props; // 取出数组最后一项 // 注意如果使用pop()方法会改变原数组 const lastValue = value.slice(-1)[0]; let initResult = abapList[cellIndex].defaultValue || []; // change事件分两种情况 // 一种是点击选项的X value值即是最终的取值 // 一种是下拉框中点击该项 进行选取操作 value值是被排除的值 if (isNaN(lastValue)) { initResult.length = 0; initResult = [].concat(value); } else { const initValue = ['', '', '期中成绩', '期末成绩', '综评成绩'][lastValue]; if ((initResult || []).includes(initValue)) { initResult = initResult.filter(e => e !== initValue); } else { initResult.push(initValue); } } // 针对上面两种操作 --------------------- const newCascaderData = []; (initResult || []).forEach(item => { const newValue = ['', '', '期中成绩', '期末成绩', '综评成绩']; const indexValue = newValue.findIndex(e => e === item); newCascaderData.push({ index: cellIndex, selectValue: [`${ typeId}`, `${ typeId}-${ indexValue}`], }); }); abapList[cellIndex].cascaderList = newCascaderData; abapList[cellIndex].defaultValue = initResult; dispatch({ type: 'archivesBookComposition/reloadABAPListData', payload: { abapList, }, }); };
转载地址:https://blog.csdn.net/weixin_45416217/article/details/116153609 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2024年04月23日 18时26分45秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Android】 常用的Intent
2019-04-26
Android中AsyncTask的简单用法
2019-04-26
【Android】 Android中Log调试详解
2019-04-26
【Android】Android中WIFI开发总结(二)
2019-04-26
【Android】Android之WiFi开发应用示例
2019-04-26
【Android】 Android adb常见问题整理
2019-04-26
【Android】 Android体系结构图
2019-04-26
【Android】 Android中spinner下拉列表的使用
2019-04-26
说说在 python 中,如何删除左右两边不需要的字符
2019-04-26
说说如何管理 Spring Boot 中的起步依赖
2019-04-26
说说如何在 Linux 中,新建账号
2019-04-26
说说如何在 linux 中搭建 FTP 服务
2019-04-26
说说如何在 Python 的正则表达式中使用分组
2019-04-26
说说 Python 正则表达式的匹配类型
2019-04-26
说说 Python 的贪心和非贪心匹配策略
2019-04-26
说说在 Python 中,如何找出所有字符串匹配
2019-04-26
说说 Python 正则表达式中的那些字符类别码
2019-04-26
说说 Spring Boot 的条件化注解
2019-04-26
说说如何使用 Python 在 word 中创建表格
2019-04-26
Python 基础知识考题与解答(2020 版)
2019-04-26