Reputation: 117
Is there a way to set action directly when defining a view without using the action helper? My view is already a link so I can't use a template with it. I would need to use the click event but then my view must know my router.
Example:
App.Link = Em.View.extend({
classNames: ['btn'],
tagName: 'a',
template: Em.Handlebars.compile("My Link"),
click: function(event) {
//I don't want to have to call this here
App.router.doSomething();
},
//What Id like to do
action: "doSomething"
})
Is this available anywhere? I couldn't find any information.
Upvotes: 1
Views: 172
Reputation: 2008
You actually can do that via Bindings and it is pretty acceptable (at least from my point of view). You end up using this quite a lot when dealing with a bunch of inner-connectivity between a lot of different view/objects. It is actually one of the major reasons to use Ember (handles a lot of the bootstrapping for you).
clickBinding: 'doSomething'
Made a fiddler so show a simple version it in action (mind you it can be a relative or absolute path). They do also cover this in the docs if you are looking for more details.
Upvotes: 1