В следующем коде я добавляю узел к графику в setTimout
, но он не отображается. Когда я перемещаю код из setTimeout
, он нарисован. Любая причина ?Cytoscape: Добавить элемент в setTimeout не получается.
var cytoscape = require('cytoscape');
var cy = cytoscape({
container: document.getElementById('container'),
layout: {
name: 'circle'
}
});
cy.add({
group: "nodes",
data: {
id: 'id1'
}
}
); // this adding is drawn
console.log(cy.nodes()); // this shows that the node with id:id1 is added
setTimeout(function() {
cy.add({
group: "nodes",
data: {
id: 'id2'
}
}
); // this one doesn't get drawn
console.log(cy.nodes()); // BUT, this shows that the node with id:id2 is added
}, 500);