javascript - How to make Ember.js load RESTAdapter data before showing view? -


i have app restadapter takes proper data server:

app.afile= ds.model.extend({   name: ds.attr( 'string' ), ...  app.store = ds.store.extend({   revision: 13,   adapter: ds.restadapter.extend({url: "myapi"}) }); 

and map this:

app.router.map(function() {   this.resource('allfiles', { path: '/allfiles' });   this.resource('onefile', {path: '/onefile/:onefile_id' }); 

and routes defined this:

app.allfilesroute = ember.route.extend({   model: function()   {       return app.afile.find();   } });  app.onefileroute = ember.route.extend({   model : function(params)   {       return app.afile.find(params.onefile_id);   } }); 

and templates:

 <script type="text/x-handlebars" data-template-name="allfiles">  {{#each controller}}     {{#linkto onefile this}}open{{/linkto}}  {{/each}}  </script>   <script type="text/x-handlebars" data-template-name="onefile">    {{name}}  </script> 

it works this: user opens app , displays allfiles template link called open. link opens template called onefile , passes onefile_id it.

when open app , click open works , displays proper name of 1 file. url set #/onefile/1 1 onefile_id. works fine.

but when refresh page (#/onefile/1) name not displayed anymore.

i've checked going on , in onefileroute model function before return id , occurs app.afile has null values fields defined. , after app loads values filled in app.afile object not displayed on view.

so looks restadapter gets data after view display.

how make work?

app.onefileroute = ember.route.extend({   model : function(params)   {       var m = app.afile.find(params.onefile_id);       // @ point m might not resolved, name empty       return m;   },   aftermodel: function(model, transition){       // @ point should resolved, happens here?       console.log(model.get('name'));   } }); 

my guess endpoint returning wrong information model id.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -