Ember,如何从自定义适配器继承

时间:2015-11-21 17:52:17

标签: javascript ember.js ember-cli

我有一个全球自定义适配器

if ($findNIF["0"]["nif"] && $findNIF["0"]["email"] && $findEmail["0"]["nif"] && $findEmail["0"]["email"]){
    echo "OK";
} else {
    echo "NO";
}

另一个特定的模型

// app/adapters/application.js
import ActiveModelAdapter from 'active-model-adapter';

export default ActiveModelAdapter.extend({
  namespace: 'api',
  host: 'http://reportsdashboard-v2.daliaresearch.com.dev'
});

正如您所看到的,存在重复定义'namespace''api'的属性。这是我尝试从 ChartsAdapter 继承 ApplicationAdapter 的原因之一。

1 个答案:

答案 0 :(得分:5)

免责声明:我是Ember的新人,所以请用批判的心态来解释

命名 CustomAdapter 类:

// app/adapters/chart.js
import ActiveModelAdapter from 'active-model-adapter';

export default ActiveModelAdapter.extend({
  namespace: 'api',
  host: 'http://reportsdashboard-v2.daliaresearch.com.dev',
  buildURL: function(type, id, snapshot) {
    return this.host + '/' + this.namespace + '/reports/' + snapshot.record.get('report.id') + '/charts/' + id;
  }
});

ChartAdapter

导入
// app/adapters/application.js
import ActiveModelAdapter from 'active-model-adapter';

const ApplicationAdapter = ActiveModelAdapter.extend({
  namespace: 'api',
  host: 'http://reportsdashboard-v2.daliaresearch.com.dev'
});

export default ApplicationAdapter;