Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Ember.js Models Challenge: ObjectController and ArrayController

Antoine Boillot
Antoine Boillot
10,466 Points

Ember.js / Stage 4 / ObjectControllers & ArrayControllers : what is the solution to the code challenge ?

Hey,

I'm currently learning Ember.js

On stage 4, I have an issue with the last code challenge : I cannot figure out why my code does not pass.

Here is below my solution :

AnimalShelter.KittensController = Ember.ArrayController.extend({
  actions: {
    sortByCuteness: function() {
      this.set('sortProperties', ['cutenessRating']);
    }
  }
});

Any clue ?

Thanks

ps : below is the full code, including my solution. I even added a Handlebars helper in index.html

js/app.js
AnimalShelter = Ember.Application.create();

AnimalShelter.Router.map(function() {
  this.resource('kittens', {path: '/'});
});

var kittens = [
  {id: '1', name: 'Meowzer', cutenessRating: 2},
  {id: '2', name: 'Squeaky', cutenessRating: 3},
  {id: '3', name: 'Fluffy', cutenessRating: 1}
]

// your code here

AnimalShelter.KittensController = Ember.ArrayController.extend({
  actions: {
    sortByCuteness: function() {
      this.set('sortProperties', ['cutenessRating']);
    }
  }
});
index.html
<!DOCTYPE html>
<html>
<head>
  <title>Animal Shelter</title>
</head>
<body>
  <script src="js/libs/jquery-1.10.2.js"></script>
  <script src="js/libs/handlebars-v1.3.0.js"></script>
  <script src="js/libs/ember-1.8.1.js"></script>
  <script src="js/app.js"></script>

  <script type="text/x-handlebars" id="kittens">
    <h1>Kittens</h1>
    <p><a href="a" {{action 'sortByCuteness'}}>Sort By Cuteness</a></p>
  </script>

</body>
</html>

3 Answers

Milo Winningham
seal-mask
.a{fill-rule:evenodd;}techdegree
Milo Winningham
Web Development Techdegree Student 3,317 Points

Hi Antoine!

You're on the right track here but this challenge is only asking you to set the default sort — you don't need an action like in the previous video.

Antoine Boillot
Antoine Boillot
10,466 Points

Hi Milo!

Ok, now I got what was wrong...And passed the challenge! Thanks a lot! :)

There is another thread that was more helpful to me for this particular challenge: https://teamtreehouse.com/forum/emberjs-models-challenge-objectcontroller-and-arraycontroller