Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 如何将依赖关系注入存储';s适配器_Ember.js_Ember Data - Fatal编程技术网

Ember.js 如何将依赖关系注入存储';s适配器

Ember.js 如何将依赖关系注入存储';s适配器,ember.js,ember-data,Ember.js,Ember Data,我使用余烬数据,需要将依赖项插入存储区的数据适配器中。以下是简化代码: window.App = Ember.Application.create({ ready: function() { this.register('database:current', this.Database); // this works fine, this.get('database') inside routes works ok this.inject('route', 'da

我使用余烬数据,需要将依赖项插入存储区的数据适配器中。以下是简化代码:

window.App = Ember.Application.create({
  ready: function() {
    this.register('database:current', this.Database);

     // this works fine, this.get('database') inside routes works ok
    this.inject('route', 'database', 'database:current');

    // but this does not work
    this.inject(App.SqliteAdapter, 'database', 'database:current');

    // also tried this:
    // this.inject('dataAdapter', 'database', 'database:current');
  }
});

App.Store = DS.Store.extend({
  revision: 13,
  adapter: App.SqliteAdapter
});

App.SqliteAdapter = DS.Adapter.extend({
  find: function(store, type, id) {
    var db = this.get('database');
    console.log(db); // this is undefined
  }
});

App.Database = Ember.Object.extend({});
为什么这个代码不起作用

版本:

DEBUG: Ember      : 1.1.2
DEBUG: Ember Data : 1.0.0-beta.3
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery     : 2.0.3 

您可以按如下方式向适配器中注入:

this.inject('adapter', 'database', 'database:current');

您可以在中看到更多的注入示例。

仍然不起作用。可能是因为更新版本的余烬数据?嗯,您使用的是相当新版本的余烬数据。你为什么在你的商店里指定第13版?我从某处复制的。我甚至需要指定修订吗?@galymzhan不,你需要not@galymzhan不确定从哪里得到的代码,但您可能希望从更简单的开始。忽略我在本例中扩展ActiveModel适配器和序列化程序的具体方式,但了解如何通过设置
App.ApplicationAdapter
(您无需将
适配器
传递到应用商店)来定义要使用的适配器类型。