jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.42k stars 714 forks source link

How to access the JSON data passed to the node #823

Closed nebc-jasonfung closed 4 months ago

nebc-jasonfung commented 4 months ago

I am using editor.addNode function and passing in a JSON object via the data attribute. How do I get this data when that node is clicked?

nebc-jasonfung commented 4 months ago

Looks like this can be solved by doing the following:

editor.on('nodeSelected', (id) => {
    console.log(editor.getNodeFromId(id).data.name);
});

editor.addNode('foo', 1, 1, 100, 100, 'foo', {name: 'test'}, "<p>Test</p>");