关于emberjs中命名约定的困惑

时间:2022-07-04 16:56:56

Perhaps some folks just know the answer, but I am trying to understand the following:

也许有些人只知道答案,但我想了解以下内容:

Say you are declaring a view:

假设您正在声明一个观点:

App.FooView = Ember.View.extend({});

App.FooView = Ember.View.extend({});

Now referencing this view in App.Router results in the following error:

现在,在App.Router中引用此视图会导致以下错误:

router.get('applicationController').connectOutlet('Foo')

router.get( '的ApplicationController')。connectOutlet( '富')

When I reference Foo the console states: Uncaught Error: assertion failed: The name you supplied Foo did not resolve to a controller FooController

当我引用Foo时,控制台指出:Uncaught Error:断言失败:您提供的名称Foo没有解析为控制器FooController

I could not find anywhere in the docs explaining the args. Perhaps the person who downvoted could actually contribute to the solution.

我无法在解释args的文档中找到任何地方。也许投降的人实际上可以为解决方案做出贡献。

1 个解决方案

#1


1  

When you connect an outlet, the router looks for both a controller and a view the having the same name as the one supplied. In the example you listed, the router is looking for a FooController and a FooView, and is not finding the controller. If you would like to specify more details you can pass an options object with the view, controller and context, like so:

连接插座时,路由器会查找控制器和视图,其名称与提供的名称相同。在您列出的示例中,路由器正在寻找FooController和FooView,并且没有找到控制器。如果要指定更多详细信息,可以使用视图,控制器和上下文传递选项对象,如下所示:

router.get('applicationController').connectOutlet( {
           outletName: 'master',
           controller: 'fooController',
           view: 'fooView',
           context: data
        }); 

From the documentation:

从文档:

connectOutlet: function(name, context) {
// Normalize arguments. Supported arguments:
//
// name
// name, context
// outletName, name
// outletName, name, context
// options
//
// The options hash has the following keys:
//
//   name: the name of the controller and view
//     to use. If this is passed, the name
//     determines the view and controller.
//   outletName: the name of the outlet to
//     fill in. default: 'view'
//   viewClass: the class of the view to instantiate
//   controller: the controller instance to pass
//     to the view
//   context: an object that should become the
//     controller's `content` and thus the
//     template's context.

edit: grammar and code format

编辑:语法和代码格式

#1


1  

When you connect an outlet, the router looks for both a controller and a view the having the same name as the one supplied. In the example you listed, the router is looking for a FooController and a FooView, and is not finding the controller. If you would like to specify more details you can pass an options object with the view, controller and context, like so:

连接插座时,路由器会查找控制器和视图,其名称与提供的名称相同。在您列出的示例中,路由器正在寻找FooController和FooView,并且没有找到控制器。如果要指定更多详细信息,可以使用视图,控制器和上下文传递选项对象,如下所示:

router.get('applicationController').connectOutlet( {
           outletName: 'master',
           controller: 'fooController',
           view: 'fooView',
           context: data
        }); 

From the documentation:

从文档:

connectOutlet: function(name, context) {
// Normalize arguments. Supported arguments:
//
// name
// name, context
// outletName, name
// outletName, name, context
// options
//
// The options hash has the following keys:
//
//   name: the name of the controller and view
//     to use. If this is passed, the name
//     determines the view and controller.
//   outletName: the name of the outlet to
//     fill in. default: 'view'
//   viewClass: the class of the view to instantiate
//   controller: the controller instance to pass
//     to the view
//   context: an object that should become the
//     controller's `content` and thus the
//     template's context.

edit: grammar and code format

编辑:语法和代码格式