Get RESTAdapter host

巧了我就是萌 提交于 2019-12-11 02:38:44

问题


RESTAdapter has the possibility to specify a url for the backend:

DS.RESTAdapter.reopen({
  url: 'https://api.example.com'
});

How can I access this property programmatically? I mean something like: DS.RESTAdapter.get('url') <-This doesn't work


回答1:


You're setting the properties on the class not the instance, thats why you can't retrieve the values. There are two possible solutions.

You can get the values from the prototype

DS.RESTAdapter.prototype.url

or you can instantiate the class and get it from there

DS.RESTAdapter.create().url



回答2:


Quick and dirty ...

NOTE: Please use only for debugging, this API is intern and will cenrtainly change in the future, so don't rely on it.

Assuming you have only one Store in your application:

App.__container__.lookup('store:main').get('adapter.url')

If you are using Chrome Dev Tools you can try to call this from the console, it should print out the url used by the default adapter used by the default Store. But it's discouraged to be used for other then for debugging.

Hope it helps




回答3:


Or

DS.defaultStore.adapter.url


来源:https://stackoverflow.com/questions/16324972/get-restadapter-host

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!