ag-grid - Angular Ag Grid - 有没有人想出一种方法来等待单元节点更新发生然后触发一个函数,比如回调?
问题描述
我cellChanged.node.setDataValue(fieldChanged, oldValue)
在事件发射器内部使用,并且在函数完成执行后(cellValueChanged)
无法弄清楚如何调用函数。setDataValue
我需要这样做来检查用户是否有权更新单元格。
这是检查的完整代码:
if(this.showPaywallNotification) {
// Okay, so the budget is above what we allow HOWEVER...
if(budget > BUDGET_AMOUNT) {
this.showPaywallNotification = false;
cellChanged.node.setDataValue(fieldChanged, oldValue)
// Note: This timeout is in place to prevent the infinite updating bug
// This is problematic because if the user changes the cells fast enough, they can get around the paywall. If I change the timeout to be smaller, the resulting change triggers the update, which ends up creating an infinite loop of updates.
setTimeout(() => {
this.showPaywallNotification = true;
}, 230)
}
}
有没有一种方法可以用更好的方法替换我的setTimeout()
功能,以始终确保用户无法通过比超时执行速度更快地更新单元格来绕过我的付费墙?
解决方案
您不必进行投票。setDataValue
不是异步函数。
此外,onCellValueChanged
如果您调用 ,将不会再次被调用node.setDataValue
。
看看这个 plunk:Cell Editing - Revert to old value。尝试将任何Age
值更新为负值。
onCellValueChanged($event) {
if ($event.colDef.field === 'age' && $event.newValue < 0) {
// debugger
$event.node.setDataValue('age', $event.oldValue);
console.log('value reverted');
}
}
让我知道是否有不清楚的地方,或者这还不够。
推荐阅读
- web-scraping - 刮掉lowes.com的产品,得到空的价格和库存
- .net-core - 从不同项目调用类而不引起循环引用
- node.js - 无服务器调用错误:“无权执行:dynamodb:BatchWriteItem on resource:arn:aws:...”
- python - 使用多个数据框合并左侧
- java - GenericMethodsAndBoundedTypeParameters 类型中的方法 countGreaterThan(T[], T) 不适用于参数 (Integer[], Integer)
- graphql - 通过 GraphQL API 检索给定 Gist 的提交
- python - 我想使用 python 求解隐式方程 y = (5.172*(10+4.472*y)^0.4)/(10+2*y)
- python - 如何通过请求获取带有标头详细信息的 json 文本?
- flutter - 从另一个类检查未来方法的状态码
- sml - 使用 foldr SML 组合