如何在Ember.Router中设置ApplicationController [英] How can i set the ApplicationController in Ember.Router

查看:111
本文介绍了如何在Ember.Router中设置ApplicationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其他任何处理Ember.Router控制器和视图的可能性?我的应用程序结构通常取决于需要处理相应依赖关系的require.js。



在我的例子中,我正在做App.ApplicationController作为主路由器控制器。



这是一个jsfiddle: http:// jsfiddle .net / mediastuttgart / uMKGt / 1 /



但是有没有机会手动设置?我发现这个提交信息 https://github.com/emberjs/ember.js/提交/ be69395f5eec4187b1df052d7386bcda45f79475 我可以看到,如何手动设置控制器和视图(无论如何不能得到这个工作)。但是找不到任何例子:

  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。 extension({
route:'/',
connectOutlets:function(router){
router.get('applicationController')。connectOutlet(App.MyView);
}
})
}),
...
});

编辑



我想详细解释一下。当我们使用require.js进行管理或依赖时,我们有多个控制器负责整个应用程序的各自部分。假设我们有一个通讯注册表。用于此业务情景的控制人结构为

   -  app 
- 控制器
---通讯
---- signup.js
--- cart
---结帐
- 查看
- 模型
- 路由器
- 模板

当我们使用自定义函数生成命名空间 Em .Provide('App.Controller.Newsletter'); ,它在 App.Controller.Newsletter 中创建一个对象。这个对象现在成为我们整个通讯应用程序的控制器基础。开始于 App.Controller.Newsletter.Signup = Ember.Controller.extend({}); 我们需要在这个实例中作为路由器的ApplicationController传递。如您所见,我们不能仅仅使用 App.ApplicationController 来为Ember.Router实例化控制器。

解决方案

不知道有关requirejs的任何内容,但我认为唯一的一个是定义一个

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

然后,当调用

  App.initialize()

框架将自动将该控制器注入路由器。


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.

解决方案

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.

这篇关于如何在Ember.Router中设置ApplicationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆