在农业网格事件中,例如onRowSelected(),“ this”是指网格对象。但是,我需要引用组件变量并且不知道该怎么做。我所做的就是这个,但这是一个hack:
initializeGridOptions() {
this.gridOptions = {
columnDefs: [
{ headerName: "Core #", field: "coreNumber", width: 100, sort: 'asc' },
onRowSelected: this.onRowSelected,
}
this.gridOptions['_this'] = this; // HACK
}
onRowSelected(event: any) {
if (event.node.selected) {
(this as any)._this.selectedNode = event.node.data;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?