Garret Alfert
Garret Alfert

Reputation: 91

Emberjs - actions get triggered 3 times on a single click

In my app using Emberjs, every action gets triggered 3 times on a single click.

For example with the following template and view:

Template:

<button {{action "removeFoo"}}>remove</button>

View with click handler:

listsView = Ember.View.create({
  templateName: 'lists',

  removeFoo: function(event) {
    event.preventDefault();
    console.log(new Date().valueOf());
  }
})

I get the following 3 outputs in the console:

1333634360209
1333634360215
1333634360217

Does anybody know what's causing this or what's the best approach to debug the problem?

Upvotes: 0

Views: 815

Answers (3)

Garret Alfert
Garret Alfert

Reputation: 91

The actual problem was, that the Ember app was part of a Rails application which had two other Ember apps already. Those Ember apps didn't have a rootElement specified. Adding a rootElement for every Ember app fixed the problem.

Upvotes: 2

pangratz
pangratz

Reputation: 16163

Using the latest Ember.js version 0.9.6 works fine, see http://jsfiddle.net/pangratz666/BxccU/

Upvotes: 0

rlivsey
rlivsey

Reputation: 2134

I'm not sure why it's being called multiple times, but are you intentionally overriding Ember.View#remove? If so you'll probably want to call this._super() so that it destroys the element etc...

Here's the definition of it in the source: https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/view.js#L770

If that wasn't your intention, you might want to call your action something else and see if resolves the problem.

Upvotes: 1

Related Questions