Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click event not firing when View inserted into Collection view

Tags:

ember.js

I'm trying to add a couple of buttons to my page at run time. The buttons are created and pushed into a containerView. See the addButtons function below.

Given a controller:

RE.MenuController =  Em.ArrayController.extend


  addButtons: ->
    console.log "addButtons"
    container = Ember.ContainerView.create()
    container.append()

    prevButton = RE.ButtonView.create()
    container.pushObject(prevButton)

and a view:

RE.ButtonView = Em.View.extend
  classNames: 'menuLink'
  tagName: 'button'
  templateName: 'button'

  click: (e) ->
    alert 'button clicked'

I'm never seeing the expected alert when I click on the button. Why wouldn't the click event be firing?

The html for the button looks like:

<button id="ember420" class="ember-view menuLink">TEST</button>

There's no data-ember-action there.

Should I be using this approach or use the action helper in the template?

thanks,

Martin

like image 432
Martin Stannard Avatar asked Dec 06 '25 08:12

Martin Stannard


1 Answers

Ember.View event handlers (in your case, the click function) are invoked by Ember's EventDispatcher which listens on the application root element and delegates events. The event dispatcher is only instantiated by an Ember.Application. Are you creating an Application? If not, the events will never be dispatched.

like image 105
rharper Avatar answered Dec 10 '25 05:12

rharper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!