How can i set the ApplicationController in Ember.Router

可紊 提交于 2019-12-21 14:36:31

问题


I there any other possibility to handle with Ember.Router controllers and views? My app structure generally depends on require.js which takes care of the corresponding dependencies.

In my example i'm doing the App.ApplicationController thing as the main router controller.

Here's a jsfiddle: http://jsfiddle.net/mediastuttgart/uMKGt/1/

But is there any chance to set this manually? I've found this commit message https://github.com/emberjs/ember.js/commit/be69395f5eec4187b1df052d7386bcda45f79475 where i can see, how to set the controller and view manually (anyway couldn't get this working). But couldn't find any example like:

App = Ember.Application.create();

App.MyController = Ember.Controller.extend({});
App.MyView = Ember.View.extend({});

Router = Ember.Router.extend({
    applicationController : App.MyController,
    root : Ember.Route.extend({
        index : Ember.Route.extend({
            route : '/',
            connectOutlets : function (router) {
                router.get('applicationController').connectOutlet(App.MyView);
            }
        })
    }),
    ...
});

EDIT

I'm trying to explain this a little bit more in detail. While we use require.js to manage or dependencies, we have multiple controllers which are responsible for their own parts of the entire application. Let's say we have a newsletter signup form. The controller used for this scenario is structured in

- app
-- controller
--- newsletter
---- signup.js
--- cart
--- checkout
-- view
-- model
-- router
-- template

As we use a custom function to generate namespaces Em.Provide('App.Controller.Newsletter'); which creates an object at App.Controller.Newsletter. This object now serves as controller base for our entire newsletter application. Beginning with App.Controller.Newsletter.Signup = Ember.Controller.extend({}); we need to pass in this instance as the "ApplicationController" for the router. As you can see, we can't just use App.ApplicationController to instantiate a controller for Ember.Router.


回答1:


Don't know anything about requirejs, but I think the only thing is to define an

App.ApplicationController = Ember.Controller.extend({...behavior here...})

and then, when calling

App.initialize()

The framework will then inject automatically this controller in the router.



来源:https://stackoverflow.com/questions/11192668/how-can-i-set-the-applicationcontroller-in-ember-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!