Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Los métodos addDiagramListener y removeDiagramListener nunca se llaman en gojs

Espero que todos estéis bien!! Estoy enfrentando algunos problemas al llamar al evento Diagram. Aquí estoy publicando algunos casos de uso que no funcionaron para mí y lo que funcionó.

CASO I) No funcionó: llamar a addDiagramListener y removeDiagramListener uno tras otro para la misma referencia de función "setLayout" no funcionó. Ninguno de ellos o ambos addDiagramListener o removeDiagramListener fueron despedidos.

 export class DiagramListenerTestClass { execute(context: any): any { let diagram = context.diagram; diagram.layout = new go.ForceDirectedLayout; diagram.addDiagramListener("LayoutCompleted", setLayout); diagram.removeDiagramListener("LayoutCompleted", setLayout); } } // Define outside the class var setLayout = function (event) { event.diagram.layout = new go.Layout(); console.log("Method called!!"); }

CASO II) Funcionó: Llamar a removeDiagramListener después de algún setTimeout, disparó addDiagramListener y removeDiagramListener.

 export class DiagramListenerTestClass { execute(context: any): any { let diagram = context.diagram; diagram.layout = new go.ForceDirectedLayout; diagram.addDiagramListener("LayoutCompleted", setLayout); setTimeout(() => { diagram.removeDiagramListener("LayoutCompleted", setLayout) }, 100); } } // Define outside the class var setLayout = function (event) { event.diagram.layout = new go.Layout(); console.log("Method called!!"); }

Nota: No estoy seguro de la razón por la que funcionó el caso II y no el CASO I. Lo que asumo para la ejecución exitosa del CASO II es que: "las llamadas para addDiagramListener y removeDiagramListener fueron tan rápidas que antes de que la función addDiagramListener 'setLayout' se llamado, el oyente es eliminado por 'removeDiagramListener' ". Entonces, para que la función se ejecute con éxito, llamé a 'removeDiagramListener' con un setTimeout de 100ms.

Por favor, déjame corregir si hay algo que no está bien. ¡Sus sugerencias serían muy útiles y apreciadas! ¡¡Gracias por adelantado!!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!