【问题标题】:Make data from store app-wide available?使商店应用程序范围内的数据可用?
【发布时间】:2015-04-22 03:08:34
【问题描述】:

我有一个 base-route 封装了我的应用程序中的所有其他路由。

我想让我通过 this.store.find('category') 从商店检索到的类别在我的应用程序中随处可用。

我尝试使用以下代码在基本控制器中检索它:

import Ember from 'ember';

export default Ember.ArrayController.extend({
  // retrieve all categories as they are needed in several places
  categories: function() {
    return this.get('store').find('category');
  }
});

并通过以下方式从子控制器创建别名:

categories: Ember.computed.alias('controllers.base.categories')

但它给出了这个错误消息:

未捕获的错误:断言失败:#each 循环的值必须是数组。你通过了 function () { 返回 this.get('store').find('category'); }

我该如何解决我的问题?

【问题讨论】:

    标签: ember.js ember-data ember-cli


    【解决方案1】:

    使其成为计算属性。

    categories: function() {
      return this.get('store').find('category');
    }.property()
    

    控制器在 2.0 中被弃用,所以我会考虑使用服务架构而不是基本控制器架构。

    【讨论】:

    • 感谢您提供的信息。我在哪里可以阅读有关该主题的信息,尤其是我现在应该如何处理此类问题?
    猜你喜欢
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多