Reputation: 15898
I wrote a first Ember.js Application, but it doesnt work properly.
My index.html
<script type="text/x-handlebars">
{{#if Songs.totalReviews}}
Read all my {{Songs.totalReviews}} reviews!
{{else}}
There are no reviews right now.
{{/if}}
{{#each Songs.songsController}}
<h3>{{title}}</h3>
<p>{{artist}} - {{genre}}</p>
{{/each}}
</script>
</body>
</html>
My app.js
Songs = Ember.Application.create({
mixmaster: 'Andy',
totalReviews: 1,
ready: function(){
alert('Ember sings helloooooooooo!');
}
});
Songs.Song = Ember.Object.extend({
title: null,
artist: null,
genre: null,
listens: 0
});
mySong = Song.create({
title: 'Son of the Morning',
artist: 'Oh, Sleeper',
genre: 'Screamo'
});
Songs.songsController = Ember.ArrayController.create({
content: [],
init: function(){
// create an instance of the Song model
var song = Songs.Song.create({
title: 'Son of the Morning',
artist: 'Oh, Sleeper',
genre: 'Screamo'
});
this.pushObject(song);
}
});
But if I open this page I just get
Read all my 1 reviews!
What about the array of the songs? Did I structure it the wrong way?
Upvotes: 0
Views: 434
Reputation: 615
it seem the problem is {{#each Songs.songsController}}
should use {{#each Songs.songsController.content}}
the problem is solved.
Upvotes: 0
Reputation: 8041
The issue is with the following snippet:
mySong = Song.create({
title: 'Son of the Morning',
artist: 'Oh, Sleeper',
genre: 'Screamo'
});
Here Song
is not defined u shud have used Songs.Song.create
instead....modify the code & everything works fine, here is the fiddle
Upvotes: 3