我们一起踩过的坑----react(antd)(二)

1.antd Upload默认值问题

需求是这样的,后台若没有图片默认值,则只有上传按钮,且只能上传一张图片;若有默认值,则显示默认头像图片, 可删除,删除之后有且只能添加一张图片,没有删除默认图片时不能添加图片

坑爹之路漫漫-----

 

图为无默认值时状态

图为有默认值状态,删除后可添加图片

首先设置defaultFileList,但是defaultFileList并不会默认添加到fileList里面

< Upload
accept= "image/*"
listType= 'picture'
beforeUpload= {this. beforeUpload }
defaultFileList= { fieldValue?[{
uid: "-1",
status: 'done',
url: `/file-server/ ${ fieldValue } `,
}]: "" }
onChange= {this. handleChange }
>
{
this. state. fileList. length>= 1? "": < Button style= {{ width: this. props. width} } >
< Icon type= "upload" /> 点击上传
</ Button >
}
</ Upload >


 2.antd表格筛选问题

antd官网上 https://ant.design/components/table-cn/#components-table-demo-custom-filter-panel

只有单列表格筛选的栗子,并没有全部表格筛选功能,坑爹啊~

需求如下:在右上角搜索,所有列搜索

首先是布局,因为我用了<Card>,所以用了extra属性,添加了一个input框,

< Card
title= { cardTitle }
id= { cardTitle }
className= "hoverable"
headStyle= {{ background: "#f2f4f5"} }
extra= {this. props. type=== "detail"? < Input placeholder= "关键字搜索"
onChange= {this. searchValue }
addonBefore= { < Icon type= "search" /> }
/>: "" }
>
</ Card >

在引入react-highligt-words插件

import Highlighter from 'react-highlight-words';

还要去除封面和序号的干扰,直接上代码,写的不好

searchValue=( e) =>{
const { columns, dataSource}= this. props
const txt= e. target. value
const data=[]
columns. forEach(( item) =>{
const id= item. id;
if( item && item. type!== "file"){
if( e. target. value){
const arr=[]
arr. push(... dataSource. filter( item =>typeof item[ id]=== "string" && item[ id]. includes( txt)=== true))
//匹配到一行两个条件,去重
for( let i= 0; i< arr. length; i++){
   let flag = true;
   for( let j= 0; j< data. length; j++){
     if( Object. is( arr[ i], data[ j])=== true){ //判断两个对象是否相同
       flag = false;
    }
  };
   if( flag){
data. push( arr[ i]);
  };
};
} else{
if( data. includes(... dataSource)=== false){
data. push(... dataSource)
}
}
item[ "render"]= text =>
< Highlighter
highlightStyle= {{ backgroundColor: '#ffc069', padding: 0 } }
searchWords= {[ this. state. searchText] }
autoEscape
textToHighlight= { text? text. toString(): "" }
/>
}
})
this. setState({
searchText:e. target. value,
dataSource:data
})
}

如果input框有数据输入,用filter筛选,push进data,再将data赋给页面渲染

如果input为空,即不用筛选,将所有数据都显示出来 ,最后实现效果如图:

 

 

3.antd模态框组件更新问题

不知道大家有没有遇到过这种情况,第一次加载模态框,数据很好的显示出来了,第二次再点击别的模态框的时候,呈现的还是第一次加载的数据,这是为什么呢???

之后各种去翻数据,传的是否有问题,但是显示数据没问题,后来在 componentDidMount中加入输出,监测到模态框只在第一次加载的时候更新数据,第二次加载其实是没有加载的,究其原因,其实是因为你点击关闭模态框的时候,只是隐藏了模态框,并没有销毁组件····坑

解决方法:在modal中加入destoryOnClose,问题迎刃而解啦,哈哈哈哈哈

< Modal
title= {this. props. title }
visible= {this. props. visibleForm }
onOk= {this. handleOk }
onCancel= {this. props. handleCancel }
okText= "确认"
cancelText= "取消"
destroyOnClose
>

  

转载于:https://www.cnblogs.com/NatChen/p/10192001.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
react-antd-treetable是一个基于React和Ant Design框架开发的树形表格组件。该组件提供了一个功能强大且易用的界面,用于展示具有树形结构的数据。 react-antd-treetable组件主要特点如下: 1. 树形结构:组件支持展示具有树形结构的数据,每个节点可以包含子节点,形成层叠的树状布局。 2. 数据排序:可通过点击表头进行排序操作,对树形表格中的数据进行升序或降序排序。 3. 行选择:可以通过点击表格的行来选择或取消选择特定的行数据。同时,也支持通过选择父节点实现对整个子节点的选中或取消选中。 4. 编辑功能:支持在表格中对特定单元格的数据进行编辑,提供了输入框等组件供用户进行修改。 5. 展开/收起:可以通过点击加号和减号来展开或收起树形表格中的子节点,以便更清晰地查看和管理数据。 6. 异步加载:支持异步加载数据,可以根据需要动态加载子节点数据,提高了性能和效率。 7. 数据过滤:组件提供了一个搜索框,可以根据用户输入的关键字来过滤和筛选需要展示的数据,方便用户快速找到所需数据。 总的来说,react-antd-treetable是一个功能丰富且易于使用的树形表格组件,适用于需要展示树形数据结构的项目。无论是对于数据展示、编辑、排序、选择还是过滤等功能,该组件都提供了完善的解决方案,方便开发者快速构建出符合需求的树形表格界面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值