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

Attributes changing #31

Open
anvarzkr opened this issue Aug 10, 2017 · 2 comments
Open

Attributes changing #31

anvarzkr opened this issue Aug 10, 2017 · 2 comments

Comments

@anvarzkr
Copy link

anvarzkr commented Aug 10, 2017

Hello, @crubier!

// 'data' from select handler method parameters
var nodes = this.state.graph.nodes;

$.each(nodes, function(index, node) {
      nodes[index].label = "new_label";
      console.log(nodes[index]);
});

this.setState({
      graph: {nodes: nodes}
});

I am using such code to change node's label on 'select' event.
But the labels are not changing. In react dev tools I can see that 'this.graph.nodes' has nodes with new labels but on the rendered graph they're not changing anyway. I could add/remove nodes or edges but can't render them modified.
Could you, please, help me with this problem?

@jo-tud
Copy link

jo-tud commented Oct 10, 2017

Same question, here. Can I update the model and the graph will update accordingly?

@Skoreto
Copy link

Skoreto commented May 9, 2018

I am new to ReactJS, but as far as I understand you should not mutate your data directly. The way I chose is to use immutability-helper library. Then changing node's label could look like this:

import imHelp from 'immutability-helper';

let actualNodesState = this.state.graph.nodes;
let nodeIndex = 3;    // index of node in an array (not vis.js node's id)

let newNodes = imHelp(actualNodesState, {[nodeIndex]: label: {$set: label}});

this.setState({
      graph: {nodes: newNodes}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants