EasyUI Forum
April 25, 2024, 07:34:54 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] dynamically add tab panel using reactJs  (Read 10958 times)
lintang
Newbie
*
Posts: 8


View Profile Email
« on: April 04, 2019, 04:11:30 AM »

i build application using reactJs and EasyUi using meteorJs framework.
i create dynamic sidebar menu with tree. but i'am very confused how to add new tab using on click event i build.
« Last Edit: May 05, 2019, 11:38:35 PM by lintang » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: April 04, 2019, 06:37:16 PM »

Please refer the code below:
Code:
<Tabs style={{height:250}}>
{
  this.state.data.map((tab,index) => (
    <TabPanel key={index} {...tab}>...</TabPanel>
  ))
}
</Tabs>
Logged
lintang
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: April 06, 2019, 01:30:31 AM »

thanks for your answer, and I was follow your code  Smiley
Code:
import React, { Component } from 'react';
import { Tabs, TabPanel } from 'rc-easyui';
import { render } from 'react-dom';

var data = [];
class TabContent extends Component {

  constructor(props){
    super(props);
    this.state = {
        data: [
          {
            title: 'Tab1',
            content: 'Content1'
          },{
            title: 'Tab2',
            content: 'Content2'
          },{
            title: 'Tab3',
            content: 'Content3'
          }
        ]
    };
  }


  handleAddTab(elem) {
      /* action ketika action menu true */
      this.state = {
          data: [
            {
              title: 'Tab1',
              content: 'Content1'
            },{
              title: 'Tab2',
              content: 'Content2'
            },{
              title: 'Tab3',
              content: 'Content3'
            },{
              title: 'Tab4',
              content: 'Content4'
            }
          ]
      };
  }

  render() {
    return (
        <Tabs id="tabpanel" scrollable style={{ width: '100%', height: '100%' }} justified>
        {
          this.state.data.map((tab,index) => (
            <TabPanel key={index} {...tab}>...</TabPanel>
          ))
        }
        </Tabs>
    );
  }
}

module.exports = TabContent;

Sorry this is my code. I'am new in react
handleAddTab is function will called from my sidebar file, I try to change data array with new data but its not got effect on my tabpanel

And, Please give me scrypt for render from other file imported on this tabpanel, Thank you very much
« Last Edit: April 06, 2019, 01:33:28 AM by lintang » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: April 06, 2019, 01:58:34 AM »

This is the code to append a new TabPanel component.
Code:
handleAddTab(){
  let data = this.state.data.slice();
  data.push({
    title: 'new title',
    content: 'new content'
  })
  this.setState({data:data})
}
Logged
lintang
Newbie
*
Posts: 8


View Profile Email
« Reply #4 on: April 07, 2019, 04:49:32 PM »

wuww ok thank you sir, i have problem with setstate. but i can fix it.
thanks you veey much
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!