[英]If Else Statements in Javascript for LiveCycle
我正在Adobe LiveCycle上创建一个将数字添加到不同字段中的表单。 我需要在最后一个字段(合格资产)中添加所有之前的字段,但要排除其中三个的总和,但要具体包括一个,但前提是该字段必须大于60000。我为第一部分编写了以下脚本(对所有字段求和),这是在我名为TotalAssets的字段中:
this.rawValue =Cash.rawValue+SavingsAccount.rawValue+ChildrensSavings.rawValue+CheckingAccount.rawValue+ValueHome1.rawValue+ValueHome2.rawValue+ValueVehicle1.rawValue+ValueVehicle2.rawValue+ValueVehicle3.rawValue+BusinessAccount.rawValue+BusinessAssets.rawValue+StocksBonds.rawValue+Retirement.rawValue+CDs.rawValue+OtherInvestments.rawValue+OtherAssets.rawValue;
此方法工作正常,但如果退休值大于60000,则不应将其添加到计算中。 这是我写的(EligibleAssets):
if (Retirement.rawValue > 60000) {
Retirement.rawValue = 0;
} else {
Retirement.rawValue == Retirement.rawValue ;
}
this.rawValue = TotalAssets.rawValue - (ValueHome1.rawValue+ValueVehicle1.rawValue +Retirement.rawValue);
当我将表单另存为PDF时,第一个字段总计可以正确计算,但是第二个字段为空白。
如果您能发现我的缺失或做错事,我将不胜感激。 谢谢!
我在这里看到两个简单的问题。
第一个问题是,当应该使用=
时,您正在使用==
。
==
-检查左侧是否等于右侧。 示例: if(x == 5) {
=
-左侧设置 到右侧的值。 示例: x = 5
在第一个示例中,我们不理会x,但是在第二个示例中,我们将 x 更改为5。
因此,您的代码应如下所示:
} else {
Retirement.rawValue = Retirement.rawValue;
}
但是,考虑到这一点,此代码实际上并没有执行任何操作。 Retirement.rawValue
不会更改。
这导致我们在代码中出现第二个错误,至少在我看来,这是一个错误。
if(Retirement.rawValue > 60000) {
Retirement.rawValue = 0;
}
这实际上会更改 Retirement.rawValue
,这可能会更改表单的Retirement字段中的内容 。 更糟的是,其可能的形式看起来相同,但采取不同的,当一些其他领域的计算,因为你已经改变了它的rawValue
。 那将是一个很难捕捉的错误。
解决方案是创建一个新变量: http : //www.w3schools.com/js/js_variables.asp
因此,现在我们可以创建一个新变量,将该变量设置为退役金额或不设置任何值,然后最后将该变量添加到其他rawValue
:
var retirementOrZero;
if(Retirement.rawValue > 60000) {
retirementOrZero = 0;
} else {
retirementOrZero = Retirement.rawValue;
}
this.rawValue = TotalAssets.rawValue - (ValueHome1.rawValue + ValueVehicle1.rawValue + retirementOrZero);
现在,我们有了一个数字,可以命名所需的任何名称,并且可以根据需要更改名称,而不会影响任何代码,但不会影响我们自己的代码。 因此,我们首先检查我们的退休值是否大于60000。如果更大,则将变量设置为0。否则,将变量设置为退休值。 然后,我们将所做的变量添加到房屋和价值成本中。
最后一个问题,它应该做吗
if(Retirement.rawValue > 60000) {
retirementValueOrZero = 0;
}
还是应该做
if(Retirement.rawValue > 60000) {
retirementValueOrZero = 60000;
}
当然,如果将其设置为60000而不是将其设置为零,则可能要命名您的变量cappedRetirementValue
或类似的名称-只需确保将其重命名即可!
希望有帮助!
编辑:您说您仅在退休价值大于60k时才添加,所以您想要的是:
if(RetirementValue.rawValue > 60000) {
retirementValueOrZero = RetirementValue.rawValue;
} else {
retirementValueOrZero = 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.