Я использую библиотеки Angular 4 и Cytoscape.js для рисования графиков. Я добавил расширение cytoscape.js-expand-collapse для реализации функции развертывания и свертывания на составных узлах. Хотя узлы расширяются и сворачиваются, я не могу слушать их события. Ниже приведены события, которые я хочу прослушать:
cy.nodes().on("expandcollapse.beforecollapse", function(event) { var node = this; ... }) Triggered before a node is collapsed
cy.nodes().on("expandcollapse.aftercollapse", function(event) { var node = this; ... }) Triggered after a node is collapsed
cy.nodes().on("expandcollapse.beforeexpand", function(event) { var node = this; ... }) Triggered before a node is expanded
cy.nodes().on("expandcollapse.afterexpand", function(event) { var node = this; ... }) Triggered after a node is expanded
Предоставляем фрагмент кода ниже:
// imported cytoscape, cytoscape-expand-collapse, etc
//Create instance of cytoscape:
this.cy = cytoscape({
container: document.getElementById('cy'),
layout: {
name: 'grid',
avoidOverlap: true,
padding: 30
}
})
// added nodes to the cy instance using cy.add
// use expandcollapse extension:
this.cy.expandCollapse({
layoutBy:null,
fisheye: false,
animate: false,
undoable: false,
zIndex: 0
});
//listen to events:
this.cy.nodes().on("expandcollapse.beforecollapse", (event) => {
console.log('1+');
}) //Triggered before a node is collapsed
this.cy.nodes().on("expandcollapse.aftercollapse", (event) => {
console.log('2+') }) //Triggered after a node is collapsed
this.cy.nodes().on("expandcollapse.beforeexpand", (event) => {
console.log('3+') }) //Triggered before a node is expanded
this.cy.nodes().on("expandcollapse.afterexpand", (event) => {
console.log('4+') })
Несмотря на то, что раскрытие-развал работает, указанные выше события не срабатывают. Есть ли здесь что-то, чего мне не хватает?