我想在初始化程序中使用存储来尝试这样做:
export function initialize(application) {
application.inject('controller', 'store', 'service:store');
this.store.createRecord('model');
}
export default {
name: 'modify-models',
initialize
};
有了这个,this.store
是未定义的。
如 the doc 所示,我尝试了 var store = application.lookup('service:store');
但 application.lookup
未定义。
我也尝试过 var store = Ember.inject.service('store');
但 store
未定义。
我找不到正确的方法。解决办法是什么?
最佳答案
您需要确保它是 instance initializer ,并且您需要使其在 ember-data
之后运行:
export default {
name: 'modify-models',
after: 'ember-data',
initialize
};
关于ember.js - 如何在初始化程序中使用存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35409966/