11

jsbin の例: http://jsbin.com/ICoLOgO/4/edit

アクションを提供する mixin がある場合、ember 1.0-rc.5 では、アクションは警告なしで呼び出されます。ember 1.0 final にアップグレードすると、非推奨の警告が表示されます。

Action handlers implemented directly on controllers are deprecated in favor of action handlers on an `actions` object

function.apply を使用せずにアクション マップで個々のアクションを公開する簡単な方法はありますか?

4

1 に答える 1

27

共通のアクションを mixin のハッシュに入れるだけactionsで、Ember がアクション ハッシュを mixin を拡張する任意のコントローラーと適切にマージするように処理しました。

App.PaginatedListController = Ember.Mixin.create({
  queryParams: ['page'],
  page: 0,

  actions: {
    nextPage: function() {
      this.incrementProperty('page');
    },

    previousPage: function() {
      this.decrementProperty('page');
    },
  }
});

App.PostsController = Ember.ArrayController.extend(App.PaginatedListController, {
  actions: {
    // controller specific actions here
  }
});
于 2014-05-15T16:20:16.207 に答える