ember.js - Use ActiveModelAdapter to make arbitrary JSON query in ember -


i'm using standard activemodeladapter in ember app of queries work ember model object.

in 1 case, however, want make arbitrary rest request json populate chart (not backed model) want go "through" activemodeladapter correct host values used.

here's what's not working:

updatechartfromindustry: function() {   ember.$.ajax({     context: this,     method: 'get',     url: 'api/v3/charts/all_risk.json',     datatype: 'json',     data: { ind: this.get('ind') }   }).then(function(json) {       ember.$('#risk-days-data').highcharts(json);     },     function(errs) {       console.log(errs);     }   ); }.observes('ind'), 

in development, query goes localhost:4200 (the ember server) rather rails backend @ localhost:3000. explicitely setting full url makes query go through without various user session informatino authenticates request.

i'm hoping simple like:

this.store.query('arbitrary url , params', ....) 

as if making normal query model or, alternately, leverage adapter:

ember.adapter.$.ajax(....)  

i'm posting "a" way this, not right way it.

the short answer adapter available (even in components) through this.container.lookup('adapter:application'). can used send ajax queries directly. think can set own adapter , override default behavior in case, able trick working way wanted using default adapter.

updatechartfromindustry: function() {   let adapter = this.container.lookup('adapter:application');    // create url. not 'chart' is, default, pluralized "charts".   // happened api.   // second parameter becomes "id" use identify   // chart name.    // http://localhost:3000/api/v3/charts/all_risk   let url = adapter.buildurl('chart', 'all_risk');     // object.data automatically converted query params   let params = { data: { ind: this.get('ind') } };    // make request , build chart response   adapter.ajax(url, 'get', params).then(function(response) {     ember.$('#my-chart').highcharts(response);   }); }.observes('ind'), 

p.s. done activemodeladapter derives ds.restadapter should allow same behavior.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -