I am new to JS and facing a problem using cytoscape.js I want to get data from a PG database and based on that create nodes. However, no nondes are being shown. In the following is my code. Does anyone have any tips? Many thanks!
window.addEventListener("DOMContentLoaded", my_function);
var data = [];
let pg = import('./pg.js')
let nodes = pg.my_nodes
for (node in nodes){
if (node !== undefined && node !== []){
data.push(node)
}
}
function my_function() {
var cy = (window.cy = cytoscape({
container: document.getElementById("cy"),
style: [{
selector: "node",
style: {
content: "data(id)"
}
},
{
selector: "edge",
style: {
"curve-style": "bezier",
"target-arrow-shape": "triangle"
}
}
],
elements: {
nodes: data,
edges: []
},
layout: {
name: "grid"
}
}));