1
我想要按钮调用控制器中的removeAlbum函数。但它什么都不做。当我点击按钮什么也没有发生,并且没有错误...我该怎么做才能解决这个问题?余烬{{action}}不起作用
这是我的模板:
<script type="text/x-handlebars" data-template-name="albums">
{{#if App.albumsController.total}}
<div><h1>Количество альбомов: {{App.albumsController.total}}</h1></div>
{{#each content in App.albumsController}}
<div class='album'>
<div class='image'>
<a {{action showAlbum content href=true}}>
<img {{bindAttr src="content.avatarUrl"}}>
</a>
</div>
<div class='info'>
<h2>
<a {{action showAlbum content href=true}}>
{{content.title}}
</a>
</h2>
<div>{{content.description}}</div>
</div>
<div class='actions'>
<div>
<button {{action removeAlbum content target="App.albumsController"}}>Delete</button>
</div>
</div>
<div class='clear'></div>
</div>
{{/each}}
{{else}}
<div><h1>Loading</h1></div>
{{/if}}
</script>
这是我的控制器:
App.albumsController = Em.ArrayController.create({
content: [],
total: null,
loadAlbums: function(){
this.set('content', []);
this.set('total', null);
var self = this;
$.post(App.connection.url, {method: 'albums.getAll', params: {user_id: App.connection.userId}}, function(response){
self.set('total', response.albums.total);
response.albums.album.forEach(function(item){
var buf = App.AlbumInList.create({
id: item.id,
title: item.title,
description: item.description,
avatarUrl: item.thumbnail_video.thumbnails.thumbnail[1]._content
});
self.pushObject(buf);
});
});
},
removeAlbum: function(x){
console.log('remove it');
}
});
嗯,在我的余烬应用程序中,控制器不能在App上找到。我发现他们只是在路由器:App.router.albumsController。也许试试这个?您也可以在您的应用程序中使用控制器而不是完全合格的路径。 – mavilein
在我的路由器中只有应用程序控制器 – user1753867
为什么你自己创建控制器?为什么不使用Ember.ArrayController.extend({...})并让框架通过调用App.initialize()来创建控制器? – mavilein