2013-10-17 43 views
10

實施例jsbin:http://jsbin.com/ICoLOgO/4/edit燼:重用上混入控制器動作最佳方式

如果我有一個混合,提供了一個作用,其中燼1.0- rc.5的行動將沒有警告被調用。升級到燼1.0最終導致折舊警告顯示:

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

是否有一個簡單的暴露在動作映射的個人行爲,而無需使用function.apply方式?

回答

26

我只是把常見的操作放在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 
    } 
}); 
+0

非常感謝!你救了我的下午:) – alem0lars

相關問題