Emler.js Router action for controller

When I use Ember Router, how can I identify the actions in the template that are connected to the controller?

Example: http://jsfiddle.net/KvJ38/3/

Unter My Profile - two actions: One of them is determined by the state and works. Two are defined on the controller. How can I make this work or use a different approach?

App.Router = Em.Router.extend({ enableLogging: true, location: 'hash', root: Em.State.extend({ // EVENTS goHome: Ember.State.transitionTo('home'), viewProfile: Ember.State.transitionTo('profile'), // STATES home: Em.State.extend({ route: '/', connectOutlets: function(router, context) { var appController = router.get('applicationController'); appController.connectOutlet(App.HomeView); } }), // STATES profile: Em.State.extend({ route: '/profile', connectOutlets: function(router, context) { var appController = router.get('applicationController'); appController.connectOutlet(App.ProfileView); } }), one: function() { alert("eins"); }, }) }); 
+5
source share
3 answers

The default task for the action is the router, but you can define another pattern:

 {{action two target="controller"}} 

And add the "two" function to the "App.ProfileController".

UPDATE

This answer, hopefully, will be fixed in mid-2012. Now (September 2014) the documentation says:

By default, the {{action}} helper runs the method on the template controller. [...] If the controller does not implement the method with the same name as the action in its action object, the action will be sent to the router, where it will be possible to process the action in the current active route of the sheet. [...] If neither the template controller nor the current active route implement the handler, the action will continue to bubble on any parent routes. Ultimately, if ApplicationRoute defined, it will have the ability to handle the action. When an action is initiated, but the corresponding action handler is not executed on the controller, the current route or any of the existing route ancestors will be issued.

+12
source

You can specify the target attribute explicitly, as @ Stéphane indicated, to send the action to another location.

If not specified, the target of the action assistant is the controller.target file. As you noted, this is usually installed on the router.

If you have a template in which you want the default target to be different, you can do this by setting the target property of the controller. For example, to set a target on the controller itself:

 App.MyController = Ember.Controller.extend({ init: function(){ this._super(); this.set('target', this); }; }); 
+4
source

The controller should not be "directly" responsible for the action. Status / route.

I believe https://github.com/emberjs/ember.js/issues/1015 will help you.

0
source

Source: https://habr.com/ru/post/918806/


All Articles