Ember RESTAdapter名称空间是否可继承?

时间:2014-12-27 00:25:33

标签: javascript ember.js

假设我们有以下代码:

App.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: '/webapp_name'
    host: 'http://localhost:8080'
});

App.PersonAdapter = DS.RESTAdapter.extend({
    namespace: '/foo/bar'
});

那么,模型App.Person定位于http://localhost:8080/webapp_name/foo/bar/person还是http://localhost:8080/foo/bar/person

1 个答案:

答案 0 :(得分:1)

是的,适配器只是一个Ember对象,可以扩展,但您的示例不是继承PersonAdapter中的ApplicationAdapter

如果您希望从App.PersonAdapter继承App.ApplicationAdapter属性,则host需要App.ApplicationAdapter延伸。

App.PersonAdapter = App.ApplicationAdapter.extend({
    namespace: '/foo/bar'
});

上面的内容现在具有从ApplicationAdapter继承的host属性,但是将覆盖名称空间,结果为http://localhost:8080/foo/bar/xxx