簡體   English   中英

灰燼從視圖發送數據導致錯誤

[英]Ember sending data from view causes error

我將視圖中的操作發送到當前的路由控制器,然后再發送到另一個控制器,以便一次編寫代碼。

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

* *不建議使用:不建議在控制器上直接實現的動作處理程序,而推薦使用Ember.ControllerMixin.Ember.Mixin.create.deprecatedSend上的actions對象(action: processPersonData on)上的動作處理程序

什么是實施此發送操作的正確方法? 僅供參考:發送操作正常運行。

此消息表明,處理操作的方法應在對象的“操作”散列下,如下所示:

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

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

這只是動作處理的新語義。

如果嘗試從視圖中調用控制器中的操作,則應按如下方式使用Em.ViewTargetActionSupport mixin:

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
        },
    },
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM