javascript - How can i set the ApplicationController in Ember.Router - Stack Overflow

I there any other possibility to handle with Ember.Router controllers and views? My app structure gener

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: /

But is there any chance to set this manually? I've found this mit message .js/mit/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.

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/mediastuttgart/uMKGt/1/

But is there any chance to set this manually? I've found this mit message https://github./emberjs/ember.js/mit/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.

Share Improve this question edited Jan 14, 2013 at 20:28 sly7_7 12k3 gold badges41 silver badges54 bronze badges asked Jun 25, 2012 at 15:47 Michael Alexander FreundMichael Alexander Freund 2663 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744132287a4559895.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信