Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Accessing element from component scope

$
0
0
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.

At the moment I am doing this:

  1.       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:

  1. 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)

  1.       can.Component.extend({
    tag: "clients-form",
            scope:  {
    client: null,
    cancel: function (context, el) {
    this.element.trigger('cancel');
    }

    },

Viewing all articles
Browse latest Browse all 3491

Trending Articles