我有一个Ember app设置,当访问/ playlist / 1时,它会按预期呈现模板。但是,未显示模型数据。我有一个带插座的playlist.hbs文件,以及带有html和把手的index.hbs的播放列表文件夹,用于显示数据。我有App.PlaylistIndexController& App.PlaylistIndexRoute已定义。
App.Router.map(function() {
this.resource('account', {path: '/account/:accountId'}, function() {
this.route('login');
});
this.resource('playlist', { path: '/playlist/:playlist_id'}, function() {
this.route('edit');
});
});
FWIW,在添加嵌套路由之前一切正常(我的控制器和路由分别定义为App.PlaylistController和App.PlaylistRoute)
"playlist":{"id":1,"name":"playlistname"}
有关如何正确显示播放列表数据的任何想法吗?
更新
App.PlaylistIndexRoute = App.AuthenticatedRoute.extend({
setupController: function(controller, model) {
this._super(controller, model);
var online = this.get('store').find('account');
this.controllerFor('playlistViewers').set('model', online);
},
});
<div id="main">
<div id="primary">
<section id="playlist">
<header class="playlist-header">
<h2>Playlist</h2>
<h1>{{name}}</h1>
</header><!--.playlist-header-->
<div class="playlist-content">
<ul>
{{#each song in songs}}
<li {{action 'play' song}} class="show-for-mobile">
<button {{bind-attr class="song.isPlaying:icon-volume-up:icon-play song.isStreaming:icon-adjust"}} ></button>
<div class="song-meta">
<span class="song-name">{{song.name}}</span>
<span class="song-artist">{{song.artist}}</span>
</div><!--.song-meta-->
</li>
{{/each}}
</ul>
</div><!--.playlist-content-->
</section><!--#playlist-->
</div><!--#primary-->
{{partial "sidebar"}}
这是我当前的播放列表/ index.hbs文件,但即使{{name}}也没有显示
答案 0 :(得分:4)
您的PlaylistIndexRoute
需要有型号。这可以是播放列表资源加载的模型。
App.PlaylistIndexRoute = App.AuthenticatedRoute.extend({
model: function() {
return this.modelFor('playlist');
}
});