【问题标题】:Confusion about naming conventions in emberjs关于 emberjs 中命名约定的困惑
【发布时间】:2012-08-06 17:14:17
【问题描述】:

也许有些人只知道答案,但我试图理解以下内容:

假设你要声明一个视图:

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

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

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

当我引用 Foo 时,控制台状态为:Uncaught Error: assertion failed: The name you supplied Foo did not resolve to a controller FooController

我在解释参数的文档中找不到任何地方。也许投反对票的人实际上可以为解决方案做出贡献。

【问题讨论】:

  • .connectOutlet('foo') 中的 "foo" 应该是小写的(不确定这是否是绝对必要的),因为我相信您在编辑之前已经有了它。你也需要一个控制器:App.FooController = Ember.Controller.extend({});(不是我投反对票)

标签: ruby-on-rails ember.js


【解决方案1】:

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

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

来自文档:

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.

编辑:语法和代码格式

【讨论】:

  • @buuda 我或多或少在 emberjs 网站上的更新指南中遇到了这个问题 - 感谢您提供我可以使用的答案。
猜你喜欢
  • 2017-04-21
  • 1970-01-01
  • 2019-04-26
  • 2020-10-17
  • 1970-01-01
  • 2013-08-11
  • 1970-01-01
  • 1970-01-01
  • 2014-06-06
相关资源
最近更新 更多