2014-03-05 24 views
0

我從視圖發送動作到當前路由控制器,然後到另一個控制器,以便編寫一次代碼。Ember從視圖發送數據導致錯誤

this.get('controller.controllers.study/study').send('processPersonData', data); 

* *棄用:直接在控制器中實施動作處理程序被淘汰,操作處理程序的上actions對象(動作:processPersonData上) 在Ember.ControllerMixin.Ember.Mixin.create.deprecatedSend

實施此發送操作的正確方法是什麼? 供參考:發送操作正確。

回答

1

此消息表示處理操作的方法應該是一個「行動」哈希下的對象,像這樣:

App.SomeController = Ember.ObjectController.extend({ 
    someVariable: null, 

    actions: { 
     processPersonData: function(context) { 
      //implementation 
     }, 
     otherAction: function(context) { 
      //implementation 
     } 
    } 
}); 

這是採取行動的處理只是新的語義。

0

如果你正試圖從您的視圖調用你的控制器的操作,您應該按如下方式使用Em.ViewTargetActionSupport混入:

App.DashboardView = Em.View.extend(
    Ember.ViewTargetActionSupport, { // Mixin here 

    functionToTriggerAction: function() { 
     var data = this.get('data'); // Or wherever/whatever the data object is 

     this.triggerAction({ 
      action: 'processPersonData', 
      actionContext: data, 
      target: this.get('controller') // Or wherever the action is 
     }); 
    }, 
}); 

App.DashboardController = Em.ObjectController.extend(

    // The actions go in a hash, as buuda mentioned 
    actions: 
     processPersonData: function(data) { 
      // The logic you want to do on the data object goes here 
     }, 
    }, 
});