Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

javascript - 在按钮上单击显示反应表(on button click display react table)

I have one react table with subcomponent, in subcomponent, I am having 2 buttons on click of each button need to show react table, please help me with this.

(我有一个带有子组件的反应表,在子组件中,每个按钮的单击上我有2个按钮需要显示反应表,请对此提供帮助。)

ex:
class Sample extends React{
firstFun=()=>{
return <ReactTable data={} columns={columns}
}
secondFun=()=>{
return <Reacttable data={} columns={columns}
}
subcompo=()=>{
// some code
<bt1 onclick={this.firstFun}/>
<bt2 onclick={this.secondFun}/>
}
render(){
return(
<ReactTable
data={}
submcomponent={this.subcompo}
/>
)}
}
  ask by Shruti Biradar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can set in state which button is clicked and active with boolean value and display different tables.

(您可以设置其状态为boolean并单击并激活哪个按钮,并显示不同的表。)

Is something like this similar to what you are looking for:

(类似于以下内容:)

class Sample extends React {
    state = {
        firstButtonActive: false,
        secondButtonActive: false
    }
    handleFirstButtonClick = () => {
        this.setState({ firstButtonActive: !this.state.firstButtonActive})
    }
    handleSecondButtonClick = () => {
        this.setState({ secondButtonActive: !this.state.secondButtonActive })
    }
    subcompo = () => {
        // some code
        <bt1 onclick={this.handleFirstButtonClick} />
        <bt2 onclick={this.handleSecondButtonClick} />
    } 

    render() {
        const { firstButtonActive, secondButtonActive } = this.state;
        return (
            <>
                <ReactTable
                    data={}
                    submcomponent={this.subcompo}
                />

                {firstButtonActive && <ReactTable data={} columns={columns}/>}

                {secondButtonActive && <ReactTable data={} columns={columns} />}
            </>
        )
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...