Javascript 余烬:存储在Application.initializer中不可用
我已经实现了一个基于文章的身份验证 因此,我在应用程序初始化时创建了一个Javascript 余烬:存储在Application.initializer中不可用,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我已经实现了一个基于文章的身份验证 因此,我在应用程序初始化时创建了一个App.Session对象: Ember.Application.initializer({ name: 'session', initialize: function (container, application) { App.Session = Ember.Object.extend({ init: function () {
App.Session
对象:
Ember.Application.initializer({
name: 'session',
initialize: function (container, application) {
App.Session = Ember.Object.extend({
init: function () {
this._super();
this.set('authToken', $.cookie('auth_token'));
this.set('authAccountId', $.cookie('auth_accountId'));
this.set('authAccountLanguage', $.cookie('auth_accountLanguage'));
},
authAccountIdChanged: function () {
var authAccountId = this.get('authAccountId');
$.cookie('auth_accountId', authAccountId);
//Load the actual account record from the server if the authAccountId is set
//Used to have for example the full name or other properties of the account
if (!Ember.isEmpty(authAccountId)) {
this.set('authAccount', this.store.find('account', authAccountId));
}
}.observes('authAccountId'),
...
我在authcountid
上有一个观察者;因此,每次更改accountId
(登录用户的id
)时,我都希望检索该用户的所有详细信息(全名、首选项等)
在Ember data 1.0.0版之前,我使用的是:
this.set('authAccount', App.Account.find(authAccountId));
这起作用了。现在我使用:this.set('authcount',this.store.find('account',authcountid))代码>
我收到错误:未捕获类型错误:无法调用未定义的方法“find”
。同样在调试器中,this.get('store')
导致未定义。我的印象是,商店在应用程序.initializer
中不可用。有人可以帮助解决此问题吗?您可以使用容器。查找('store:main')
这将返回在容器中注册的存储:
var store = container.lookup('store:main');
this.set('authAccount', store.find('account', authAccountId));
如果container.lookup('store:main')
返回未定义的,你会怎么做?嗯,这是奇怪的container.lookup('store:main')
应该仍然可用。@BenMorganIO FWIW,这个问题可能会得到解决,因为你在初始值设定项的导出默认值中添加了。