目前我用
D3
使用
display
财产,但它可能是反对
React
-做事的方式。这是可行的,但如果有一个解决方案,我会选择另一个:
changedDiffGenes = (pageNum) => {
let prevId = '#diff_chart_' + (this.state.currPageDiffGenes - 1);
let currId = '#diff_chart_' + (pageNum - 1);
d3.select(prevId).style("display","none");
d3.select(currId).style("display","block");
this.setState({
currPageDiffGenes: pageNum
})
}
{
this.get_analysis_charts(this.chartTypes[parseInt(this.state.activeKey)]).map((chart_arr, idx) => {
return <div id = {'diff_chart_' + idx} style={{display: idx === 0 ? 'block' : 'none',
visibility: this.state.currPageDiffGenes === (idx + 1) ? 'visible' : 'hidden' }}>
<img src = {chart_arr[0]} style = {{height:"200px", width:"300px"}}/>
<img src = {chart_arr[1]} style = {{height:"200px", width:"300px"}}/>
</div>
})
}
<div style = {{marginLeft: '35%'}}>
<UltimatePaginationBootstrap4 key = 'diff_genes_pagination'
totalPages = {this.get_analysis_charts(this.chartTypes[parseInt(this.state.activeKey)]).length}
onChange = {this.changedDiffGenes}
currentPage = {this.state.currPageDiffGenes}/>
</div>
所以,在函数内部
onChange = {this.changedDiffGenes}
由调用
UltimatePaginationBootstrap4
(这是从
react-ulitmate-pagination
github
page)我来回切换
显示
属性介于
block
和
none
. 它肯定比使用
d3
我在这里找到了相关的解决方案:
How to hide elements without having them take space on the page?