我正在關注文檔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-電網實際。類似問題:[作爲引用傳遞的角5/4/2方法不在作用域中](https://stackoverflow.com/questions/48557364/1417185) – Paritosh
[作爲引用傳遞的Angular 5/4/2方法的可能的副本是不在範圍內](https://stackoverflow.com/questions/48557364/angular-5-4-2-method-passed-as-reference-is-not-in-scope) – Paritosh