问题
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