我有我通過使用Ember.inject灰燼服務要組件
應用程序/通知/ service.js
import Ember from 'ember';
export default Ember.Service.extend({
store: Ember.inject.service('store'),
notifications: function() {
return this.get('store').findAll('notification');
},
});
然後我的應用程序/組件/應用程序的通知組件調用服務/component.js:
import Ember from 'ember';
export default Ember.Component.extend({
notifications: Ember.inject.service('notifications'),
});
然後我在/app/components/app-notifications/template.hbs
組件模板但我不能讓它顯示我的模型的數據?我似乎無法在文檔中找到關於此的更多信息,所以我想知道是否有人知道如何做到這一點?
解決方案
好了,我得到了它與
import Ember from 'ember';
export default Ember.Service.extend({
store: Ember.inject.service('store'),
notifications: function() {
return this.get('store').findAll('notification');
}.property(),
});
的'store'是一種服務,所以你不需要在其他服務中使用它。此外,'store.findAll'返回一個承諾,並在服務中沒有足夠的時間來解決它。 Ember等待在'routes'的'model'中解決的承諾。 –
顯然要獲得一個服務內部的燼數據存儲我不得不稱之爲http://stackoverflow.com/questions/29881771/how-to-inject-store-in-service-ember-js 因此,對於第二部分,這是否意味着我需要調用afterModel或.findAll('notification')。then(function(){? –
您可以使用Ember.RSVP.hash({}返回多個模型。 )''' –