cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1242
Views
2
Helpful
1
Replies

Create a customized Node class with clickNode event handler

amd.lin01
Level 1
Level 1

Hi all,

I would like to create a node. If I click or select the node, there will be a message in the console.

Here are my codes.

nx.define('MyExtendNode', nx.graphic.Topology.Node, {

    view: function(view) {

         view.content[2].events.clickNode = this._nodeClick;

         return view;

    },

    methods: {

        init: function(options) {

            this.inherited(options);

        },

        dispose: function() {

            this.inherited();

        },

        _nodeClick: function(sender, event){

            console.log('node clicked')

        }

    }

});

But there is no message in console.

How could I create a customized Node class?

1 Reply 1

aaikepae
Cisco Employee
Cisco Employee

Hi Tzuche,

About your customized node class, you should do two small modification.

1. view.content[2].events.clickNode should be view.content[2].events.click

2. Because NeXt view engine will parse the view json. So you should follow the syntax of view definition. like:

view.content[2].events.click = "{#_nodeClick}"

I am thinking we should add your syntax support too. Will update that sooner.

I made an example for your reference.

http://codepen.io/NEXTSUPPORT/pen/YqONOj?editors=0010

For create customized node class, you can refer these example. Extend - > Extend Node

https://developer.cisco.com/site/neXt/discover/demo/

Thanks,

Abu