1

我想要按钮在控制器中调用 removeAlbum 函数。但它什么也没做。当我单击按钮时,什么也没有发生,也没有错误......我应该怎么做才能解决这个问题?!

这是我的模板:

<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');
  }
});
4

1 回答 1

1

尝试将您的目标设置为控制器而不是 App.albumsController。应该解决问题。

<button {{action removeAlbum content target="controller"}}>Delete</button>
于 2013-01-16T22:20:24.830 回答