假设我们有以下代码:
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://本地主机:8080/foo/bar/person
?
最佳答案
是的,适配器只是一个 Ember 对象并且可以扩展,但是您的示例没有从 ApplicationAdapter
继承 PersonAdapter
。
如果您希望从 App.ApplicationAdapter 继承
.host
属性,则需要从 App.ApplicationAdapter
扩展 App.PersonAdapter
App.PersonAdapter = App.ApplicationAdapter.extend({
namespace: '/foo/bar'
});
上面现在将具有从 ApplicationAdapter 继承的 host
属性,但 namespace 将被覆盖,结果为 http://localhost:8080/foo/bar/xxx
关于javascript - Ember RESTAdapter 命名空间可以继承吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27663302/