reactjs - 在标签点击上显示内容 - React
问题描述
我对 React 很陌生,想显示 2 个选项卡,第一个选项卡单击应该显示我拥有的画布,第二个选项卡应该显示下拉列表。我现在在页面中拥有所有三个。
我的页面看起来像这样 - 2 个选项卡、一个下拉菜单和一个画布。
如何在第一个选项卡单击和下拉菜单上绑定画布 div 以在第二个选项卡单击时显示。
编辑代码:
export class Graph extends Component {
constructor(props) {
super(props);
this.state = {
Vdata: null,
Edata: null,
iconData : iconsData,
currentIndex: 0
}
this._tabClick = this._tabClick.bind(this);
this.MainGraphComponent = this.MainGraphComponent.bind(this);
this.CustomizedGraphComponent = this.CustomizedGraphComponent.bind(this);
}
CustomizedGraphComponent(){
return(
<div className={style.container} style={{ width: '100%', paddingTop:20}}>
<DropdownButton>
{
//elements
}
</DropdownButton>
</div>
)
}
MainGraphComponent(){
<div ref={(n) => {
this.graphContainer = n;
return;
}} id="container"
style={{height: '100%', width: '100%'}}
/>
}
_tabClick(clickedIndex) {
const {currentIndex} = this.state.currentIndex;
if(clickedIndex !== currentIndex) {
this.setState({currentIndex: clickedIndex })
}
}
render (){
return (
<div className={style.container} style={{height: '100%', width: '100%'}}>
<Tabs
tabs={[
{
name: 'Main Graph',
title: 'Main Graph',
component: <this.MainGraphComponent/>
},
{
name: 'Customized Graph',
title: 'Customized Graph',
component:<this.CustomizedGraphComponent/>
}
]}
onTabClick={this._tabClick}
/>
</div>
);
}
解决方案
你考虑使用状态吗?就像下拉菜单的显示可以设置为最初为无的状态值,然后在选项卡上单击 setState 以更改值。
推荐阅读
- node.js - 多个快速的外部 POST 请求
- javascript - 如何对同一动作类中的方法调用动作?
- micronaut - Picocli 命令中的注入与 micronaut 之间的互操作性
- docker - 如何在单个 AWS EC2 实例上设置 3 节点 Elasticsearch 集群?
- enums - 用其他值替换地图中的空值
- android - Android:获取芯片图标点击事件
- oracle - 权限缺失 - Oracle System 事件触发问题 12c
- javascript - 如何在 iframe 中实现 Frame Buster Javascript
- import - 如何在 git 子模块中组织多个协议缓冲区文件?
- javascript - 选择禁用不将选定的值传递给 php 代码