覆盖DS.Store ember-cli [英] Overwrite DS.Store ember-cli

查看:64
本文介绍了覆盖DS.Store ember-cli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码需要在 store.init 上运行。

I have some code that needs to run on store.init.

我尝试扩展默认存储在 app / store.js 中,ember-cli似乎把它当成一个商店,但在 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如果您使用该版本或更高版本,该文件现在是 app / stores / application.js (或 app / application / store .js 如果您使用的是pods)。

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).

覆盖商店是一样的,只有文件名/位置已更改。如果您使用的版本低于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆