node.js - 访问循环时,在循环外声明的变量确实会发生变化 - 节点
问题描述
现在,当 if 明显进入循环并且应该更改为 false 时,我的函数将返回 true,如下所示:
private recalculateGridViewBottomToTop = (window: fin.OpenFinWindow): boolean => {
const toolbarWindow = fin.desktop.Window.getCurrent();
if (this.windows != null) {
let shiftFromRightToLeft = true;
this.windows.forEach((win) => {
window.getBounds((currentBounds) => {
win.getBounds((bounds) => {
if (bounds.top >= currentBounds.bottom! && bounds.left === currentBounds.left) {
win.leaveGroup();
win.setBounds(bounds.left, bounds.top - currentBounds.height, bounds.width, bounds.height);
toolbarWindow.mergeGroups(win);
shiftFromRightToLeft = false;
}
});
});
});
return shiftFromRightToLeft;
}
shiftFromRightToLeft 应该已经从true变为false我想知道为什么没有发生这种情况?
解决方案
根据您的代码,如果条件为真,if (bounds.top >= currentBounds.bottom! && bounds.left === currentBounds.left) {
则 shiftFromRightToLeft 将更改false
,否则将保持不变true
看看下面的例子:
if(true){
let a = true
if(false){
a = false
}
console.log(a) // output : true
}
推荐阅读
- outlook - Office365 应用程序问题
- wildfly - Infinispan 在 1 级清理中使用挂线
- php - 如何在codeigniter中根据第一个循环的ID添加另一个循环
- jms - 将 Spring 集成部署到 WebSphere ND 8.5.5
- java - 有没有一种很好的方法来检测 JTable 列之间的边界上的(双击)鼠标单击?
- python - 来自txt文件的输入和使用函数的简单绘图
- python - 如果与功能 API 一起使用,TensorFlow lambda 将增加一维
- electron - nodeIntegration:false 时的自定义电子标题栏问题
- html - Formik 没有显示在 nextjs 页面上?
- amazon-web-services - AWS 开发工具包 - 支持自定义信任库