Class Ember.ViewTargetActionSupport
Ember.ViewTargetActionSupport
is a mixin that can be included in a
view class to add a triggerAction
method with semantics similar to
the Handlebars {{action}}
helper. It provides intelligent defaults
for the action's target: the view's controller; and the context that is
sent with the action: the view's context.
Note: In normal Ember usage, the {{action}}
helper is usually the best
choice. This mixin is most often useful when you are doing more complex
event handling in custom View subclasses.
For example:
1 2 3 4 5 6 7 |
App.SaveButtonView = Ember.View.extend(Ember.ViewTargetActionSupport, { action: 'save', click: function() { this.triggerAction(); // Sends the `save` action, along with the current context // to the current controller } }); |
The action
can be provided as properties of an optional object argument
to triggerAction
as well.
1 2 3 4 5 6 7 8 |
App.SaveButtonView = Ember.View.extend(Ember.ViewTargetActionSupport, { click: function() { this.triggerAction({ action: 'save' }); // Sends the `save` action, along with the current context // to the current controller } }); |
apply (obj)
Inherited from Ember.Mixin packages/ember-metal/lib/mixin.js:491
- obj
- returns
- applied object
create (arguments)
Inherited from Ember.Mixin packages/ember-metal/lib/mixin.js:444
- arguments
detect (obj) Boolean
Inherited from Ember.Mixin packages/ember-metal/lib/mixin.js:518
- obj
- returns
- Boolean
reopen (arguments)
Inherited from Ember.Mixin packages/ember-metal/lib/mixin.js:457
- arguments
triggerAction (opts) Boolean
Inherited from Ember.TargetActionSupport packages/ember-runtime/lib/mixins/target_action_support.js:51
- opts
- Hash
- (optional, with the optional keys action, target and/or actionContext)
- returns
- Boolean
- true if the action was sent successfully and did not return false
Send an "action" with an "actionContext" to a "target". The action, actionContext and target will be retrieved from properties of the object. For example:
1 2 3 4 5 6 7 8 9 |
App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, { target: Ember.computed.alias('controller'), action: 'save', actionContext: Ember.computed.alias('context'), click: function() { this.triggerAction(); // Sends the `save` action, along with the current context // to the current controller } }); |
The target
, action
, and actionContext
can be provided as properties of
an optional object argument to triggerAction
as well.
1 2 3 4 5 6 7 8 9 10 |
App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, { click: function() { this.triggerAction({ action: 'save', target: this.get('controller'), actionContext: this.get('context'), }); // Sends the `save` action, along with the current context // to the current controller } }); |
The actionContext
defaults to the object you mixing TargetActionSupport
into.
But target
and action
must be specified either as properties or with the argument
to triggerAction
, or a combination:
1 2 3 4 5 6 7 8 9 |
App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, { target: Ember.computed.alias('controller'), click: function() { this.triggerAction({ action: 'save' }); // Sends the `save` action, along with a reference to `this`, // to the current controller } }); |