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 Loading Arrays of JavaScript objects

QUIZ Problem

https://teamtreehouse.com/library/emberjs/models/challenge-1-loading-arrays

Please Help And Here's my code :

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

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

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

AnimalShelter.KittensRoute = Ember.Route.extend({ model: function() { return kittens; } });
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>Here is a list of all of our kittens:</p>
    <ul>
      <!-- your code here -->
    </ul>
  </script>

</body>
</html>

Thanks Mates!

1 Answer

Ralph Simon
seal-mask
.a{fill-rule:evenodd;}techdegree
Ralph Simon
Front End Web Development Techdegree Student 30,103 Points

Use an {{#each}} block and refer to the property you want to display in curly braces: {{name}}:

<ul>
  <!-- for #each item (in this case object) in the array *kittens[i]* -->
  {{#each}}
    <!-- print out the *names* property => kittens[i].name -->
    <li>{{names}}</li>
  {{/each}}
</ul>

** Ember 1.7.0 is deprecated Be sure to check out the latest Ember Guides, since it's now at 2.7.0. A lot of the things taught on Ember here at Treehouse have become obsolete. If you'd like to use Ember be sure to check out their guides, since it provides some excellent tutorials.