0

I have an ArrayController (documents) which displays a list of ObjectsControllers (document) for its content.

My ArrayController template (Documents):

{{#each document in model}}
   {{render "document" document}}
{{/each}}

The issue I am facing is that the "sortProperties" and "sortAscending" properties on the ArrayController are no longer having any effect. I assume this is because I am looping "model". If I loop "each document in controller", the document ObjectControllers dont seem to get the model assigned to them as a call to .model then throws an undefined error. Should I be looping "controller" or "model"? If the answer is model, how can I sort it and if the answer is controller, how can I get the model set on each controller?

2
  • 1
    Does the arrangedContent property, rather than model work? By default, model is an alias for content, and arrangedContent is the ordered property for it. Commented Feb 26, 2015 at 16:55
  • @DRobinson Thanks, using arrangedContent gave me what I needed - the sorted array and each controller also got its model. If you provide your comment as an answer I will accept it Commented Feb 26, 2015 at 17:41

2 Answers 2

2

Rather than modifying the base model, the sorted collection is exposed as arrangedContent.

To explain why it's arrangedContent rather than arrangedModel, in Ember's ControllerMixin content is defined as an alias for model, but it used to be the other way around.

Sign up to request clarification or add additional context in comments.

Comments

0

You may have to set the itemController property on your ArrayController (Documents).

See here: http://emberjs.com/api/classes/Ember.ArrayController.html

Edit: Also, you had it right the first time with {{#each document in controller}}. Doing it straight from the model will ignore configuration in your controller, which includes sorting rules you may have.

4 Comments

It is set but has no effect.
But if I loop controller, the model does not get assigned to the individual ObjectControllers. The template displays the model values, but calling .model on an ObjectController results in an undefined error
Whenever you're accessing properties of an object such as your controller, you need to use .get and .set methods provided by Ember. Try this.get('model'), does that work?
If you are trying to trigger an action with the model, try passing it from the template, e.g. {{action 'save' this}} instead of {{action 'save'}} and then trying to access the model from the controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.