ember.js - Ember afterRender component / non-async AJAX -
ember.js - Ember afterRender component / non-async AJAX -
imagine component renders html table. info table comes remote json.
another part of component relies on html table beingness rendered (with json data).
on component's init event, retrieve json , set info component utilize render table.
i can't utilize afterrender hook farther process table, because when afterrender fired, table exists without json data.
i noticed afterrender hook outside component works (the table rendered), i'd break encapsulation running code belongs within component.
i maybe json synchronously, or perhaps promise within promise? how latter? mean on component's init hook, how create promise returns when promise within returned?
or how can approach ember way?
you can chain hell out of promises.
var items = []; this.set('items', items); $.getjson('/colors').then(function(results){ results.foreach(function(item){ item.color +=" pretty"; }); homecoming results; }).then(function(prettyresults){ prettyresults.foreach(function(item){ items.pushobject(item); }); }); http://emberjs.jsbin.com/oxidivu/724/edit
super deep convoluted promises
new ember.rsvp.promise(function(resolve){ resolve($.getjson('/colors')); }).then(function(results){ // isn't nail til json returned results.foreach(function(item){ item.color +=" pretty"; }); homecoming new ember.rsvp.promise(function(resolve){ ember.run.later(function(){ resolve(results); }, 4000); }); }).then(function(prettyresults){ // isn't nail til 4 sec resolve done prettyresults.foreach(function(item){ items.pushobject(item); }); }); http://emberjs.jsbin.com/oxidivu/725/edit
ajax ember.js
Comments
Post a Comment