我设置了一个在 Fixture Adapter 开启的情况下运行良好的应用程序。
这是我用来渲染的模板:
<div class="large-7 columns" id="song-list">
<div class="playlist-meta row">
<div class="large-12 columns">
<h4 class="subheader">Playlist</h4>
<h1 class="playlist-title">{{controller.name}}</h1>
</div>
</div>
{{#view App.SortableView}}
{{#each song in controller.songs}}
<li class="row song">
<button {{action "playSong" song}} class="toggle-play"><span class="entypo play"></span></button>
<h4 class="subheader song-artist"><a href="#">{{song.artist}}</a></h3>
<h3 class="song-title"><a href="#">{{song.name}}</a></h3>
</li>
{{/each}}
{{/view}}
</div>
但是,当我使用 REST 适配器时,歌曲不会呈现。播放列表名称本身仍会呈现,但不会呈现歌曲。
这是以 JSON 形式返回给我的内容:
{"playlist":{"id":1,"name":"playlist","songs":[{"id":1,"name":"Song Name","artist":"Song Artist","soundcloud":"/tracks/1"}]}}
我使用夹具数据时定义的模型:
App.Playlist = DS.Model.extend({
name: DS.attr('string'),
songs: DS.hasMany('App.Song'),
});
App.Song = DS.Model.extend({
name: DS.attr('string'),
artist: DS.attr('string'),
soundcloud: DS.attr('string'),
playlist: DS.hasMany('App.Playlist'),
});
App.Playlist.FIXTURES = [
{
id: 1,
name: 'Playlist Name',
songs: [1, 2, 3],
}];
App.Song.FIXTURES = [
{
id: 1,
name: 'Song Name',
artist: 'Song Artist',
soundcloud: '/tracks/12345',
}];