【问题标题】:call method on click column menu单击列菜单上的调用方法
【发布时间】:2020-01-19 09:56:04
【问题描述】:

我是 ag-grid 的新手。我正在尝试添加自定义列菜单项。

我在构造函数中写了这个:

this.gridOptions = <GridOptions>{
     getMainMenuItems: this.addColumnMenu
};

所以,每当我单击列的过滤器图标时,都会调用“addColumnMenu”。

现在,在 addColumnMenu 中,我已将菜单项添加为

 var menuItems = params.defaultItems.slice(0);
 menuItems.push({
           name: 'Stats', action: this.callStat }
 });

它的给定this.callStat 没有定义。因为我在this 没有得到任何东西

这里有什么问题?

【问题讨论】:

    标签: angularjs ag-grid


    【解决方案1】:

    如果 addColumnMenu 需要访问 'this',则需要绑定。实现这一目标的一种方法:

    this.gridOptions = <GridOptions>{
      getMainMenuItems: this.addColumnMenu.bind(this)
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多