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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:重启Vue学习之旅:适合起步的Vue-ant-design&&Vuex学习项目
下一篇:我在react中用到的发布-订阅模式

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月23日 18时26分45秒