En mi aplicación Next.js, estoy usando la biblioteca de menús contextuales de Cytoscape para crear un submenú que se actualiza dinámicamente para incluir opciones específicas según el tipo de nodo que se haya seleccionado. Los valores de los elementos del submenú ya se pasan al menú general a través de un objeto evt
. He intentado usar submenu.push()
; sin embargo, me encuentro con el siguiente error:
Error de sintaxis: Token inesperado, esperado ","
Antes de reunir la funcionalidad dentro del método push()
para tomar elementos de forma dinámica de evt
para crear objetos a partir de ellos, intenté ejecutar el método push()
en objetos predefinidos para probar si este concepto funcionaría en general; sin embargo, no lo hizo para mí. Realmente agradecería si alguien pudiera señalar lo que puedo haber estado haciendo mal y explicar cómo puedo agregar dinámicamente elementos en un submenú, si es posible. He incluido mi código a continuación:
const options = { evtType: 'cxttap', menuItems: [ { id: 'one', content: 'This is the first option in the menu', selector: 'node', onClickFunction(evt) { genericFunctionName(evt, 'one') }, }, { id: 'two', content: 'This is the second option in the menu', selector: 'node', onClickFunction(evt) { genericFunctionName(evt, 'two') }, }, { id: 'three', content: 'This is the third option in the menu', selector: 'node', onClickFunction(evt) { console.log(evt.target.data('properties')); }, submenu: [ { id: 'submenuOne', content: 'This is the first option in the submenu', tooltipText: 'blue', onClickFunction: function () { console.log("The first option in the submenu was clicked on") }, }, { id: 'submenuTwo', content: 'This is the second option in the submenu', tooltipText: 'blue', onClickFunction: function () { console.log("The second option in the submenu was clicked on") }, }, ], submenu.push( { id: 'submenuThree', content: 'This should be the third option in the submenu', tooltipText: 'blue', onClickFunction: function () { console.log("The third option in the submenu was clicked on") }, }, ), }, ], };
FWIW, estoy usando Cytoscape Context Menus v4.1.0.