How do you access RESTAdapter's host and namespace inside a route or controller?

后端 未结 1 924
北荒
北荒 2021-01-04 02:03

I have a few custom AJAX requests that I use inside of some controllers and routes, for example:

 var loginRoute = Ember.Route.extend({

   actions: {

              


        
相关标签:
1条回答
  • 2021-01-04 02:58

    turns out you can access the Adapter from the store via this.store.adapterFor('application')

    The new submitLogin method could look like this:

     submitLogin: function(user, pass) {
    
       var data = { username: user, password: pass },
           host = this.store.adapterFor('application').get('host'),
           namespace = this.store.adapterFor('application').namespace,
           postUrl = [ host, namespace, 'login' ].join('/'); // http://192.168.2.10/api/v1/login
    
       Ember.$.post(postUrl, data).then();
     }
    
    0 讨论(0)
提交回复
热议问题