joker1979
joker1979

Reputation: 191

Ember Actions: Using Variables Action Names

From the Ember Documentation, I've been looking at this:

<div class='intro'> {{intro}} </div> {{#if isExpanded}} <div class='body'>{{body}}</div> <button {{action 'contract'}}>Contract</button> {{else}} <button {{action 'expand'}}>Show More...</button> {{/if}}

Note - that all the action names refer to a hardcoded value such as 'expand'.

What I would like to do is something like this:

<button {{action variable}}>Show More...</button>

where variable is defined in the controller or model.

Has anyone tried to do this?

Upvotes: 1

Views: 139

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

Works out of the box

<div {{action foo}}> Click Me</div>

App.IndexController = Em.ArrayController.extend({
  foo:'bar',
  actions:{
    bar: function(){
      alert('bar');
    },
    baz: function(){
      alert('baz');
    }
  }
})

Example (change the input box from bar to baz): http://emberjs.jsbin.com/beyesawe/1/edit

Upvotes: 1

Related Questions