1.在项目中用 antd的tree组件的时候,遇到两个问题css
1.文件名太长的话 会超出容器 很难看,解决方法以下node
` 引入css在global下设置
:global {
.ant-tree li .ant-tree-node-content-wrapper{
height:auto;
}
.ant-tree-node-content-wrapper{
white-space: normal;
max-width: 100%;
}
}api
`数组
2.节点都展开的话 会过高了。也会撑开盒子,影响美观。
解决方法: 一方面 展开一个的时候 ,能够收起同级别其余已经展开的。代码以下,在tree的api里 展开回调设置,同时 要tree组件绑定 state的展开节点数组。antd
onExpand = (a,b) => { if(b.expanded){ if(a.length>0){ a.splice(0,a.length-1) } } this.setState({ expandedKeys:a }) };
app
上边的代码有一个问题 ,就是不能 跨级 收起。改后的代码以下this
onExpand = (a,b) => { if(b.expanded){ if(a.length>0){ a.splice(0,a.length-1) } this.setState({ expandedKeys:a }) }else{ const key = b.node.props.children.map((obj,index)=>{ if(a.indexOf(obj.key)>-1){ return obj.key; } return '' }).filter((v,index)=> v!== ''); //index 是点击收起节点的下级展开节点 const index = a.indexOf(key[0]); //由于展开的时候会收起兄弟节点 因此这里应该只有一个 if(index>0){ a.splice(0,index + 1); //从0开始 删除到点击的下一级已展开节点 } this.setState({ expandedKeys:a }) } };
另外一方面就是 展现部分 显示 查看更多... 这个我看看怎么弄。spa