CanJS future element event binding

736 Views Asked by At

The CanJS documentation has an example like this:

var Todos = can.Control.extend({
    init: function( element , options ) { ... },

    'li click': function( li ) { ... },
    'li .destroy {destroyEvent}': function( el, ev ) { 
        // previous destroy code here
    }
});
// create Todos with this.options.destroyEvent
new Todos( '#todos', { destroyEvent: 'mouseenter' } );

However, if #todos is created after new Todos is called, no event is bound the future element, or if a method within Todos removes a pre-created #todos dummy as deemed necessary. How can I rebind custom events within a Control? After a Control instantiation call?

1

There are 1 best solutions below

1
On

Just use Control.on(); http://canjs.com/docs/can.Control.prototype.on.html

You can specifiy which event to be listen to or just call the function without parameters like this the control listen to all events.