在樹形的table中论熙,如果數(shù)據(jù)結(jié)構(gòu)中的children的值是[ ]福青,沒有值,table還是會顯示展開按鈕脓诡,希望的結(jié)果的是沒有children或是沒有值就不顯示展開按鈕无午,就使用到expandIcon這個屬性。
下面是我的例子
customExpandIcon=(props)=> {
if(props.record.children.length > 0){
if (props.expanded) {
return <a style={{ color: 'black',marginRight:8 }} onClick={e => {
props.onExpand(props.record, e);
}}><Icon type="minus-square" style={{fontSize:16}}/></a>
} else {
return <a style={{ color: 'black' ,marginRight:8 }} onClick={e => {
props.onExpand(props.record, e);
}}><Icon type="plus-square" style={{fontSize:16}}/></a>
}
}else{
return <span style={{marginRight:8 }}></span>
}
}
<Table bordered={ true }
loading={ loading }
columns={ columns }
dataSource={ dataList }
rowKey={(row) => { return row.value }}
pagination={ pagination }
expandIcon={(props) => this.customExpandIcon(props)}
/>
代碼中是判斷了props,record的值祝谚。children是否有值宪迟,然后返回,如果沒有就返回一個span交惯。
image.png