本文介绍了如何从农业网格拖动和调用服务掉落事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ag-grid上设置了触发拖放事件的选项:

I have an ag-grid set up with options to trigger drag and drop events:

this.gridOptions = {
      columnDefs: this.getColumnDefs(),
      rowDragManaged: true,
      onRowDragEnter: this.onRowDragEnter,
      onRowDragEnd: this.onRowDragEnd,
...

我也有一个简单的服务

export class myService {
...
   public doSomething(): void {
        ...
   }
}

似乎我无法从 onRowDragEnd 事件内调用 doSomething 服务函数-获取无法读取对象的undefined属性'doSomething'....onRowDragEnd 错误.

It seems I cannot call the doSomething service function from within the onRowDragEnd event - getting a cannot read property 'doSomething' of undefined... at Object.onRowDragEnd error.

我知道服务已定义并且可以正常工作,可以从网格组件的init函数调用 doSomething ,所以我只是不确定如何调用网格外部的内容或任何解决方法?

I know the service is defined and working correctly, doSomething can be called from the grid component's init function, so I'm just not sure how I can call something external to the grid or any workaround ?

推荐答案

箭头函数将在其词法上下文中执行,而与调用者无关.试试这个:

Arrow functions will execute in their lexical context regardless of the caller. Try this:

this.gridOptions = {
      columnDefs: this.getColumnDefs(),
      rowDragManaged: true,
      onRowDragEnter: (event: RowDragEvent) => {
           this.onRowDragEnter(event);
      },
      onRowDragEnd: (event: RowDragEvent) => {
           this.onRowDragEnd(event);
      }
...

我更新了此答案,以便您可以将事件中的参数传递给处理程序.

I updated this answer so you can pass the params from the event to your handler.

这篇关于如何从农业网格拖动和调用服务掉落事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 03:19