覆盖 DS.Store ember-cli [英] Overwrite DS.Store ember-cli
问题描述
我有一些代码需要在 store.init
上运行.
I have some code that needs to run on store.init
.
我尝试在 app/store.js
中扩展默认 store,ember-cli 似乎把它作为一个 store 捡起来,但是 this.store
中的对象是不是商店
I tried extending the default store in app/store.js
, ember-cli seems to pick it up as a store, but the object in this.store
is not a store
我的店铺定义:
import DS from 'ember-data';
export default DS.Store.extend({
init:function(){
console.log('watatLoL')
}
});
推荐答案
根据 Peter Wagenet 的说法,这在 Ember Data beta 19 中发生了变化.如果您使用该版本或更高版本,该文件现在是 app/store/application.js
(如果您使用的是 Pod,则为 app/application/store.js
).
According to Peter Wagenet, this has changed in Ember Data beta 19. If you're using that version or later, the file is now app/stores/application.js
(or app/application/store.js
if you're using pods).
覆盖存储是一样的,只是文件名/位置发生了变化.如果您使用的 Ember Data 版本低于 beta 19,则可以使用旧的 app/store.js
文件.
Overwriting the store is the same, only the file name/location has changed. If you're using a version of Ember Data lower than beta 19, you can use the old app/store.js
file.
我知道这是旧的,但我不得不回答另一个问题,所以我想我会更新这个.默认情况下,Ember-CLI 解析器将查找 app/store.js
,因此您可以在那里声明您的覆盖存储.
I know this is old, but I had to answer this for another question, so I figured I would update this. By default, the Ember-CLI resolver will look for app/store.js
, so you can declare your overridden store there.
// app/store.js
import DS from 'ember-data';
export default DS.Store.extend({
init: function() {
console.log('Using custom store!');
return this._super.apply(this, arguments);
}
});
这篇关于覆盖 DS.Store ember-cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!