vendredi 19 juin 2015

Ember: How to get computed properties from a nested model?

First: I have no idea how to work with promises in Ember.js. I want to call a property of my controller which depends on async model-data which is also nested.

Also, my model looks something like that:

+-------------+         +------------+ 
| Method      | hasMany |  Practice  | 
|             +--------->            | 
|             |         |            | 
+-------------+         +------------+ 
                              |        
                              | hasMany
                        +-----v------+ 
                        | Alpha      | 
                        |            | 
                        |            | 
                        +------------+

So I created something like this:

allAlphas: function() {

  var self = this;
  var returnValue = "nichts";

  var promises = {
    allAlphas: self.get('model.method').then(function(method) {
      //get the practices
      return method.get('practices');
    }).then(function(practices) {
      //get the alphaSField in EVERY practice
      //the alphasField is the (hasmany 'alpha')member in practice
      var alphasFields = practices.getEach('alphas');
      return Ember.RSVP.all(alphasFields).then(function() {
        return alphasFields;
      });

    }).then(function(alphasFields) {

      // here: get all the alphas via promise or something

    })
  };


  Ember.RSVP.hash(promises).then(function(results) {

    // return all the alphas (of all pracitces in the method) in some way 
  });


}.property()

There are two Problems (like already metioned in the comments):

  1. How to load nested hasMany async models like all alphas in all practices.
  2. How to return the complete result as a property in the RSVP.hash-Method for use in templates or something

Can anybody help me?




Aucun commentaire:

Enregistrer un commentaire