【发布时间】:2017-07-29 12:48:25
【问题描述】:
我正在关注文档here 将上下文菜单项添加到我的网格中。问题是从 getContextMenuItems 的范围(在示例中),我无法访问组件中的任何其他方法或变量。这可能吗?示例如下:
private varIWantToAccess: boolean = false;
function getContextMenuItems(params) {
var result = [
{ // custom item
name: 'Alert ' + params.value,
action: function ()
{
window.alert('Alerting about ' + params.value);
this.varIWantToAccess = true; // Builds fine, but throws a run time exception, since this "this" context is different than the one that has "varIWantToAccess"
}
},
....
return result;
}
谢谢!
【问题讨论】:
-
这实际上与 ag-grid 无关。类似问题:Angular 5/4/2 method passed as reference is not in scope
标签: ag-grid ag-grid-ng2