Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Loop with == works but !== does not

gchammer
Level 2
Level 2

I have a process in es4 that loads data from a data base in to a form.

The number of rows in not know.

It loads in to a table fine.

The use is to select one of the items to work on.

This works if they delete 1 at a time.

It would be faster to delete what they did not select.

When I change the line to LicenseFeeDetailsId.rawValue !==fSelected all but the first is deleted no mater which is selected?

How can I delete everyone that in not selected?

//works!!
var fSelected = this.rawValue; // selected fee id
var vRows = FeeDetailsTable._Row1.count-1; //row count-1
xfa.resolveNode("ChangeRequestForm.Table1.Row1.Cell1").rawValue = fSelected; //works
for(var i=0;i>=vRows;i++){ // loop through table for(var i=vRows;i>=0;i--){
if(FeeDetailsTable.resolveNode("Row1[" + i + "]").LicenseFeeDetailsId.rawValue ==fSelected ){ //find selected row --seems to loop reverse !== does not work.
  FeeDetailsTable._Row1.removeInstance(i);//works!!
}
}
;
LicenseFeeRoot.FeeDetailsSub.numOfFees.rawValue = FeeDetailsTable.Row1.instanceManager.count; // good! up date fee count

2 Replies
radzmar
Level 10
Level 10

Hi,

there are 2 versions of the equal/not equal operators.

== and != are the lazy ones that don't compare the types of the values you're testing.

=== and !== are the strict ones, that also compare the type.

Here's a small example to demonstrate:


var a = 1, b = true;



if (a === b) {


  // Shown whenn == is used, because a is a number and b is interpreted as a number too


  // Here happens a implicit type conversion of the bolean value into a number


  xfa.host.messageBox("a is equal to b");


} else {


  // Shown when === is used, because a is a number and b is a boolean value


  // The values are not comparable


  xfa.host.messageBox("a not equal to b");


}


So your script may fail unexpected if when you use the strict versions without knowing the type of the values you compare.

Try this script.


var fSelected = this.rawValue,


     vRows = FeeDetailsTable._Row1.count-1;


     xfa.resolveNode("ChangeRequestForm.Table1.Row1.Cell1").rawValue = fSelected; //works



for (var i = vRows; i >= 0; i -= 1) {


  var vNode = FeeDetailsTable.resolveNode("Row1[" + i + "]");


    if (vNode.LicenseFeeDetailsId.rawValue != fSelected) {


    FeeDetailsTable._Row1.removeInstance(i);


    }


}