Ember.js promise closure

I'm trying to loop over what I think is Ember's promise, but all I can get back is an object when it should be an array.

jsbin: http://emberjs.jsbin.com/qakine/1/edit

If I just iterate over the elements in the template then I have no problem, but I want to be able to interact with the elements of the array in my controller. Any help was appreciated.

+3


source to share


2 answers


A few things here, let me see if I can remember them:

When you have a route under a resource, the routes and controllers of that route must have a parent name.

App.Router.map(function() {
  this.resource("parent", function(){
    this.route("child");
  });
});

App.ParentChildRoute...

App.ParentChildController...

      

Handlebars cannot access normal functions from your controller, this must be converted to a computed property.

App.ParentChildController = Ember.ObjectController.extend({
  middleNames: function(){
    ...
  }.property('middles.[]')
});

      



Naming is case sensitive

{{#each name in middlenames}}

      

it should be

{{#each name in middlenames}}

      

Example: http://emberjs.jsbin.com/cowibi/1/edit

+4


source


I created a new example based on yours to keep things clear. You can check it out here:

http://emberjs.jsbin.com/hokabe/4/edit

For a ram route model

, if the return value is a promise, the route will wait for the promise to resolve and pass the resolved value to the model

controller property .

And the App.Parent

instance property middles

returns a promise (it is actually an instance DS.PromiseArray

) that will resolve the middles array (it is actually an instance DS.ManyArray

).



so for getting children you can simply do this:

App.ParentMiddlesRoute = Ember.Route.extend({
  model: function() {
    return this.modelFor('parent').get('middles');
  }
});

      

Note that the argument modelFor

is the route name, not the model name. This means "Get a model from a given route".

0


source







All Articles