【问题标题】:Ember App Kit: Controller without Route is not recognized?Ember App Kit:没有路由的控制器无法识别?
【发布时间】:2014-03-27 14:48:07
【问题描述】:

正如我在这里的几个问题中提到的那样,我正在迁移一个已经存在且正在运行的 Ember 项目以使用 Ember App Kit,我遇到了几个问题......这是另一个以前不是问题的“问题”:)

我有一个NotificationCollectionController,它位于app/controllers/notification/collection.js 下。

文件 'app/controllers/notification/collection.js':

export default Ember.ArrayController.extend({
  addNotification: function (options) {
    // some code
  },
  notifyOnDOMRemove: function (notification) {
    this.removeObject(notification);
  }
});

由于这是通过命名插座呈现的通知的控制器,因此我没有为它声明路由。

在我的ApplicationRoute 中,我想在一个函数中访问这个控制器

文件: 'app/routes/application.js'

import BaseRoute from 'appkit/routes/base';

export default BaseRoute.extend({
  addGlobalNotificationCollection: function () {
    var controller = this.controllerFor('notificationCollection');
    // some more code...
  }
});

但是,一旦应用程序启动并调用了这段代码,我就发现了以下错误:

“断言失败:名为 'notificationCollection' 的控制器可以 找不到。确保这条路线存在并且已经存在 至少输入一次。如果您访问的控制器不是 与路由相关联,确保控制器类是明确的 已定义。”

这是什么意思,为什么会抛出?我该怎么做才能再次让它运行

【问题讨论】:

    标签: ember.js ember-app-kit


    【解决方案1】:

    我没有意识到 提示 已经在 Ember App Kit WebpageNaming Conventions 部分给出:

    它说,控制器的命名约定是,例如:stop-watch.js

    如果它是一个路由控制器,我们可以像这样声明嵌套/子控制器: app/controllers/test/index.js

    所以我把我的NotifcationCollectionController 放在controllers/notification-collection.js 中并像Route#controllerFor('notification-collection') 一样称呼它,一切都按预期工作:)

    【讨论】:

    • 我在这里遇到了类似的问题,您的 Route 文件看起来如何?干杯
    猜你喜欢
    • 2018-10-04
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 2018-11-11
    相关资源
    最近更新 更多