ember.js - Ember: How to get computed properties from a nested model? -


first: have no idea how work promises in ember.js. want call property of controller depends on async model-data nested.

also, model looks that:

+-------------+         +------------+  | method      | hasmany |  practice  |  |             +--------->            |  |             |         |            |  +-------------+         +------------+                                |                                       | hasmany                         +-----v------+                          | alpha      |                          |            |                          |            |                          +------------+ 

so created this:

allalphas: function() {      var self = this;    var returnvalue = "nichts";      var promises = {      allalphas: self.get('model.method').then(function(method) {        //get practices        return method.get('practices');      }).then(function(practices) {        //get alphasfield in every practice        //the alphasfield (hasmany 'alpha')member in practice        var alphasfields = practices.geteach('alphas');        return ember.rsvp.all(alphasfields).then(function() {          return alphasfields;        });        }).then(function(alphasfields) {          // here: alphas via promise or        })    };        ember.rsvp.hash(promises).then(function(results) {        // return alphas (of pracitces in method) in way     });      }.property()

there 2 problems (like metioned in comments):

  1. how load nested hasmany async models alphas in practices.
  2. how return complete result property in rsvp.hash-method use in templates or something

can me?

edit 06/20/2015

as @kingpin2k suggested, ive added gist better understanding of problem: https://gist.github.com/marcmanhart/e5c1d91e8fdfd876de37

just return array, , populate array after fact.

allalphas: function() {   var self = this,       returnvalue = [];    this.get('model.method').then(function(method) {     //get practices     return method.get('practices');   }).then(function(practices) {     //get alphasfield in every practice     //the alphasfield (hasmany 'alpha')member in practice     var alphas= practices.geteach('alphas');     ember.rsvp.all(alphas).then(function(resolvedalphas) {       resolvedalphas.foreach(function(afs){         returnvalue.pushobjects(afs.toarray());       });     });   });    return returnvalue; }.property() 

update

it looks pushobjects doesn't ed collection (or maybe doesn't promises underneath, didn't much). should use resolved values instead of promises sent in (alphas vs resolvedalphas in code below).

example: http://emberjs.jsbin.com/cinobetoyu/1/edit?js,output


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -