Ember.js 具有余烬数据查询的PromiseProxy服务

Ember.js 具有余烬数据查询的PromiseProxy服务,ember.js,promise,ember-data,proxy-classes,Ember.js,Promise,Ember Data,Proxy Classes,我正在尝试设置一个PromiseProxy服务,该服务返回一个余烬数据模型,但结果似乎没有设置content属性 我的服务如下所示: import Ember from 'ember'; const { computed, inject, ObjectProxy, PromiseProxyMixin } = Ember; export default ObjectProxy.extend(PromiseProxyMixin, { isServiceFactory: true, sto

我正在尝试设置一个PromiseProxy服务,该服务返回一个余烬数据模型,但结果似乎没有设置
content
属性

我的服务如下所示:

import Ember from 'ember';

const { computed, inject, ObjectProxy, PromiseProxyMixin } = Ember;

export default ObjectProxy.extend(PromiseProxyMixin, {
  isServiceFactory: true,
  store: inject.service(),

  promise: computed({
    get() {
      var store = this.get('store');

      return store.findRecord('community', window.community.id);
    }
  })
});
然后,我将此服务注入以下位置:

export function initialize(container, application) {
  application.inject('controller', 'community', 'service:community');
  application.inject('route', 'community', 'service:community');
  application.inject('model', 'community', 'service:community');
  application.inject('component', 'community', 'service:community');
}

export default {
  name: 'community',
  after: 'store',
  initialize: initialize
};
然后我在我的应用程序路径中将它作为一个模型,作为一种解决方法,因为我的整个应用程序都依赖于这个模型 它在整个过程中都会被使用,并且预计会出现在那里

export default Ember.Route.extend({
  model() {
    return this.get('community');
  }
});
问题是它会转到其他路由,并且
社区
对象上的属性不存在,即未设置
内容
。还有
community.isPending
true
。CP确实被命中,数据返回(我在CP中用
然后
进行了测试)

以下是一个完整的要点示例:


编辑

所以我找到了一个解决办法:

  promise: computed({
    get() {
      var store = this.get('store');

      return store.findRecord('community', window.community.id)
        .then(data => {
          this.set('content', data);
          return data;
        })
    }
  })

似乎它没有设置内容,因为模型已经被代理了?

余烬数据已经将其对象包装在ObjectProxy中,您可以将对象设置为您的服务

此外,这种语法在未来版本的初始值设定项语法中被弃用,因为它已转移到实例初始值设定项中,但没什么大不了的

 initialize: function (container, application) {
    // the store will be available from the container, 
    // and the name of the store changes depending on which version you are using.
    var store = container.lookup('service:store'),
        community= store.find('community', id);
    application.register("service:community", community, { instantiate: false });
    application.inject("controller", "community", "service:community");
    application.inject("route", "community", "service:community");
    application.inject("component", "community", "service:community");
}

然后你仍然可以从模型中返回社区,在模型挂钩之前等等。

这是我目前拥有的,但它需要
延迟准备状态
,因为我需要在应用程序的其他部分中解析模型。我正试图从
迁移到
,并希望迁移到2.x,因此必须使用实例初始值设定项。