We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class CategoryTree extends Component { constructor(props) { super(props); this.state = { data: { core: { data: [{ "id": "98", "parent": "#", "text": "[Sample] Product Category", "state": { "opened": true, "selected": true } }, { "id": "99", "parent": "98", "text": "[Sample] Sub Category", "state": { "opened": true, "selected": true } }, { "id": "100", "parent": "#", "text": "[Sample] Product Category 2", "state": { "opened": true, "selected": true } }, { "id": "101", "parent": "100", "text": "[Sample] Sub Category 2", "state": { "opened": true, "selected": true } }, { "id": "102", "parent": "100", "text": "[Sample] Sub Category 3", "state": { "opened": true, "selected": true } }, { "id": "103", "parent": "100", "text": "[Sample] Sub Category 4", "state": { "opened": true, "selected": true } }, { "id": "104", "parent": "100", "text": "[Sample] Sub Category 5", "state": { "opened": true, "selected": true } } ] }, plugins: ['checkbox'], checkbox: { three_state: false // to avoid that fact that checking a node also check others } }, selected: [], }; } handleClick() { const newData = this.state.data.core.data[0].children.slice(); newData.push({ text: 'New child node' }); this.setState({ data: { core: { data: [ { text: 'Root node', children: newData } ] } } }); } handleChange(e, data) { this.setState({ selected: data.selected, }) } render() { const { categories } = this.props; const data = { core: { data: categories }, plugins: ['checkbox'], checkbox: { three_state: !true// to avoid that fact that checking a node also check others } } return ( <div> <button onClick={() => this.handleClick()}>Add node</button> <br /><br /> {(categories.length === 0)? null: <TreeView treeData={data} onChange={(e, data) => this.handleChange(e, data)} />} <br /> <p>Selected nodes: {this.state.selected.join(', ')}</p> </div> ); } } export default CategoryTree
When setting the data in local state it's working fine
The text was updated successfully, but these errors were encountered:
No branches or pull requests
When setting the data in local state it's working fine
The text was updated successfully, but these errors were encountered: