如何修复 Appmaker 中的最大调用堆栈大小超出错误
How to fix Maximum call stack size exceeded error in appmaker
我目前正在验证一个日期框小部件,以防止在 30 天宽限期后提交。日期验证工作正常,但在警报提示后它并没有下降(即使点击几下,我仍然在这里存货)。日期框也不会为空。
function checkDateValidate(widget) {
var form = app.pages.Newitem.descendants;
var otdate = form.otDateBox.value;
var date = new Date();
var pastdate = date.setDate(date.getDate() - 31);
if(otdate <= pastdate) {
alert('Date exceeds within 30 days grace period is invalid.');
form.otDateBox.value = null;
}
}
我希望清除日期框小部件。
这个错误有时会发生,因为有一个无限循环正在进行,这就是你的情况。了解 onValueChange 事件处理程序和 onValueEdit 事件处理程序之间的区别非常重要。
onValueChange:
This script will run on the client whenever the value property of this widget changes. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue.
onValueEdit:
This script will run on the client whenever the value of this widget is edited by the user. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue. Unlike onValueChange(), this runs only when a user changes the value of the widget; it won't run in response to bindings or when the value is set programmatically.
为什么会这样?
由于您的逻辑是在 onValueChange 事件处理程序上设置的,因此每次 dateBox 小部件值更改时都会触发此事件,即使以编程方式更改也是如此;因此,form.otDateBox.value = null;
一遍又一遍地触发逻辑。之所以反复触发是因为你的比较逻辑:
if(otdate <= pastdate)
这里,otdate的值变成了null,转换成数字Number(null)
后的值是0(零)。 pastdate的值显然是一个大于零的数,例如1555413900712。很明显,零小于或等于 1555413900712,这就是你触发无限循环的原因。
所以,总而言之,只有一种方法可以解决这个问题。在 onValueEdit 事件处理程序而不是 onValueChange.
中设置逻辑
我目前正在验证一个日期框小部件,以防止在 30 天宽限期后提交。日期验证工作正常,但在警报提示后它并没有下降(即使点击几下,我仍然在这里存货)。日期框也不会为空。
function checkDateValidate(widget) {
var form = app.pages.Newitem.descendants;
var otdate = form.otDateBox.value;
var date = new Date();
var pastdate = date.setDate(date.getDate() - 31);
if(otdate <= pastdate) {
alert('Date exceeds within 30 days grace period is invalid.');
form.otDateBox.value = null;
}
}
我希望清除日期框小部件。
这个错误有时会发生,因为有一个无限循环正在进行,这就是你的情况。了解 onValueChange 事件处理程序和 onValueEdit 事件处理程序之间的区别非常重要。
onValueChange:
This script will run on the client whenever the value property of this widget changes. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue.
onValueEdit:
This script will run on the client whenever the value of this widget is edited by the user. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue. Unlike onValueChange(), this runs only when a user changes the value of the widget; it won't run in response to bindings or when the value is set programmatically.
为什么会这样?
由于您的逻辑是在 onValueChange 事件处理程序上设置的,因此每次 dateBox 小部件值更改时都会触发此事件,即使以编程方式更改也是如此;因此,form.otDateBox.value = null;
一遍又一遍地触发逻辑。之所以反复触发是因为你的比较逻辑:
if(otdate <= pastdate)
这里,otdate的值变成了null,转换成数字Number(null)
后的值是0(零)。 pastdate的值显然是一个大于零的数,例如1555413900712。很明显,零小于或等于 1555413900712,这就是你触发无限循环的原因。
所以,总而言之,只有一种方法可以解决这个问题。在 onValueEdit 事件处理程序而不是 onValueChange.
中设置逻辑