Skip to content
New issue

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

react this.Setstate method cannot change TreeView structure? #174

Open
baizp opened this issue Jul 21, 2022 · 3 comments
Open

react this.Setstate method cannot change TreeView structure? #174

baizp opened this issue Jul 21, 2022 · 3 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@baizp
Copy link

baizp commented Jul 21, 2022

import React, { Component } from "react";
import { Panel, TreeView, TreeViewItem } from "@playcanvas/pcui/react";

export default class Hierarchy extends Component {
  modelHierarchy = [{ title: "test1", key: "111" }];

  componentDidMount() {
    this.modelHierarchy.push({ title: "add", key: "222" });

    **//pcui bug?????? Cannot dynamically change the tree,Or what should I do**
    this.setState({ modelHierarchy: this.modelHierarchy });

  }

  mapNodes = (nodes) => {
    return nodes.map((node) => (
      <TreeViewItem text={node.title} key={node.key}>
        {node.children &&node.children.length > 0 && this.mapNodes(node.children)}
      </TreeViewItem>
    ));
  };

  render() {
    return (
      <Panel class="hierarchy" width={256} resizable="right" panelType="normal">
        {this.modelHierarchy.length > 0 && (
          <TreeView allowReordering={false} allowDrag={false}>
            {this.mapNodes(this.modelHierarchy)}
          </TreeView>
        )}
      </Panel>
    );
  }
}
@yaustar yaustar added bug Something isn't working help wanted Extra attention is needed and removed bug Something isn't working labels Jul 21, 2022
@baizp
Copy link
Author

baizp commented Jul 21, 2022

"modelHierarchy" has indeed changed!

<div>{this.modelHierarchy.length + ""}</div>

2 is displayed here, but the tree is not updated. @ellthompson

@willeastcott
Copy link
Contributor

willeastcott commented Jul 22, 2022

Hey @josflesan - any thoughts on this? I'm not quite sure what the question is to be honest, @baizp. Can you explain in more detail what this issue is about?

@baizp
Copy link
Author

baizp commented Jul 25, 2022

TreeView

Oh, ok, in fact, after modifying the data, React actively calls the render method, but TreeView has not been modified successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants