Search code examples
eventsbuttonviewember.js

2 buttons, same action, how do I tell which button triggered the action in Ember


I have a simple button that has an action.

<button {{action "slide" target="view"}} class="slide up">Slide up</button> 

Make that two,

<button {{action "slide" target="view"}} class="slide left">Slide down</button> 

Both of these have the same action that is handled by the containing view, something like this:

App.ViewName = Ember.View.extend({
   actions:{
      slide: function(){
            console.log("which button triggered the slide action?");
       }
   }

});

In the above piece of code, my console log states my quandary. I am not sure how I can identify which button {the Slide Up OR the Slide Down} triggered the slide action.

I mean, this is basic straightforward stuff in jQuery where you can simply use the 'event' to determine the calling button. But in Ember, all these concepts seem to desert me.


Solution

  • honestly I'd make it two different actions, but you can send a value to the action

    {{action slide "up"}}
    
    slide: function(type){
      console.log(type);
    }