AngularJS 1.6 + ES6 - 返回 jquery ui-grid 回调数据给控制器

AngularJS 1.6 + ES6 - Returning jquery ui-grid callback data to controller

我正在我的控制器中定义一个 jquery ui-grid 组件,其缩小示例如下所示:

class myController {
    constructor($scope) {        

        this.$scope = $scope; 

        this.Grid = {                               

            selectionSettings:{
                clientHandler:function(key,object,data){
                    console.log(key);
                    console.log(object);
                    console.log(data);                    
                    console.log(this);
                    return data;                        
                    //the scope of this function is different from the controller scope.                          
                    }              
           }
       }

       receiver(data){
             doSomething(data);
       }
    ...

我的想法是,当我 select 网格中的一个条目时,clientHandler 中的函数被触发。然后我希望此函数 将该数据传递给此 class.

中的接收函数

但是由于这个 clientHandler 函数和 receiver() 处于不同的范围 ,我无法直接使用 this关键字。

Whosebug 上的其他答案建议使用 $scope 对象来完成相同的任务,但我无法这样做。

clientHandler 函数调用 receiver() 需要什么?

任何gui舞蹈都受到热烈欢迎。谢谢

感谢 Adelin 的提醒

这是最终的工作代码:

class dashboardController {
    constructor(dashboardService, $scope) {
        this.$scope = $scope;      

        var self = this;

        this.Grid = {

            selectionSettings:{                
               clientHandler:function(key,object,data){
                   self.receiver(data);                 
            }                
        }

        receiver(data){
             this.selected = data;
             this.$scope.$apply(); //to propagate the change to the UI, if needed
         }

   }

ES6 箭头函数的存在是为了提供词法 this 并避免 self = this 技巧,这在 ES6 中通常是不必要的:

clientHandler: (key,object,data) => {
  this.receiver(data);   
}