I have a cancel button inside my component, this button calls a cancel function in the scope, this in turn triggers an event on the component element.
- can.Component.extend({tag: "clients-form",scope: function (attrs, parentScope, element) {return {client: null,cancel: function (context, el) {$(element).trigger('cancel');}}},
But it is kind of ugly that I need to use a function for the scope in order to get a ref to the element.
I also see this:
- init: function(element, options) {this.scope.attr("element", element);},.. and then use this.attr('element'
Isn't there a simpler way? e.g (but this doesn't work)
- can.Component.extend({tag: "clients-form",scope: {client: null,cancel: function (context, el) {this.element.trigger('cancel');}},