angular - 从 this.gridApi.ForEachNode 访问 componentParent
问题描述
我需要根据父容器中存在的选定日期选择默认的 ag 网格行。我无法componentParent
从节点函数内部引用或“this”
this.gridApi.forEachNode(function (node) {
If(node.data.dueDate
===this.parentContainer.selectedDueDate) {
node.setSelected(true)
}
});
我得到'this' is undefined
错误。我无法gridOptions
使用
gridOptions.context.componentParent.selectedDueDate
任何让这个工作的提示将不胜感激。
谢谢西德
解决方案
If(node.data.dueDate === this.parentContainer.selectedDueDate)
"If"
你这里有一个错字,I
它的大写字母应该是if(node.data.dueDate === this.parentContainer.selectedDueDate)
并且还使用箭头方法而不是函数,因为this
它的范围是function
,但this
可以在外部访问箭头方法
使用胖箭头方法,您可以执行以下操作:~
this.gridApi.forEachNode(node => {
if(node.data.dueDate === this.parentContainer.selectedDueDate) {
node.setSelected(true);
}
});
或者你需要bind(this)
使用正常的功能,比如
this.gridApi.forEachNode(function(node) {
if(node.data.dueDate === this.parentContainer.selectedDueDate) {
node.setSelected(true);
}
}.bind(this));
推荐阅读
- java - 如何在 java EE 8 中使用相同的实体管理器实现通用 DAO
- wordpress - 使用 CDN 从 og:image 更改域
- php - 我用 foreach 得到重复的结果
- angular - 如何使用烧瓶将 Angular signaturePad blob 保存到 AWS S3
- java - 如何确定是否需要使用 @Bean 进行注释
- rust - 将向量解析为正确的类型
- reactjs - 如何在外部设置反应最终表单的表单状态?
- reactjs - 如何从命名功能组件调用父类组件功能
- android - 无法为 StreamDownloadTask 使用 continueWith 定义任务
- google-sheets - 如何通过按电子邮件地址对行进行分组来创建和发送表格 - GoogleSheets