我编写了第一个 Ember.js 应用程序,但它不能正常工作。
我的 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>
我的 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);
}
});
但是如果我打开这个页面,我就会得到
Read all my 1 reviews!
歌曲的排列怎么样?我是否以错误的方式构建它?