相关疑难解决方法(0)

使用上下文菜单时的范围问题

我正在按照此处的文档向我的网格添加上下文菜单项。问题是,从 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;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

ag-grid ag-grid-ng2

5
推荐指数
2
解决办法
5620
查看次数

标签 统计

ag-grid ×1

ag-grid-ng2 ×1