How do you bind views to third party library events?


#1

How can you bind to external events if you wrap let’s say a jquery ui plugin with an ember view?

I tried doing this:

App.SomeView = Ember.View.extend({
    classNames: ['some', 'classes'],
    templateName: 'some',
    didInsertElement: function() {
        this.$().on('external_event', this.someCallback);
    }
});

And this:

App.SomeController = Ember.ObjectController.extend({
    appendSomeView: function() {
        var view = App.SomeView.create();
        view.append();

        view.on('external_event', this.someCallback);
    }
});

But no luck, perhaps I’m doing something wrong?


#2

My bad I was using the wrong event name by mistake, the first example does work.


#3

don’t forget to remove the listener on willDestroyElement you don’t want to accidentally leak those unmanaged event handlers.


#4

Thanks @stefan will do