[英]Ember, how to inherit from a custom Adapter
I have a global custom Adapter : 我有一个全球定制适配器 :
// app/adapters/application.js
import ActiveModelAdapter from 'active-model-adapter';
export default ActiveModelAdapter.extend({
namespace: 'api',
host: 'http://reportsdashboard-v2.daliaresearch.com.dev'
});
And another specific for one Model : 另一个特定于一个模型 :
// 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;
}
});
As you can see there is a duplication defining the attributes 'namespace' and 'api' . 如您所见,存在定义属性'namespace'和'api'的重复。 This is one of the reasons I'm trying to inherit the ApplicationAdapter from the ChartsAdapter . 这是我尝试从ChartsAdapter继承ApplicationAdapter的原因之一 。
Disclaimer: I'm a newby in Ember so take this explanation with critical mind set 免责声明:我是Ember的新人,所以请用批判的心态来解释这个问题
Naming the CustomAdapter class: 命名CustomAdapter类:
// 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;
Importing it from the ChartAdapter : 从ChartAdapter导入它:
// app/adapters/chart.js
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
buildURL: function(type, id, snapshot) {
return this.host + '/' + this.namespace + '/reports/' + snapshot.record.get('report.id') + '/charts/' + id;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.