简体   繁体   中英

Populate table from array in LiveCycle Designer

I am relatively new to Javascript and have gotten my head around some of the basic language and functions used for creating Forms in LiveCycle Designer ES4.

I have 4 check boxes (say "check1", check 2...), and 4 predefined arrays ( "array1", array2....). I have a table below all these with 3 columns, (col1, col2, col3).

What I want to do is this:

  • When I check "check1", I want to populate col2 of the table with array1.
  • Then add a new row for each piece of data in the array.
  • I want do the same for the other checkboxes as well, adding onto the table as required.

I've tried a heap of different options, but none seem to be able to work. At this stage I can't even get one array to populate the table, let alone multiple.

This is my current code: (the commented out section was just a try for joining the arrays)

var array1 = new Array("one","two","Three","Four","Five");
var array2 = new Array("this","that", "and this");
var array3 = new Array("another one");
var array4 = new Array("Finally this");
var k = [];

//if(check1.rawValue == "Yes")

//{k = k.concat(array1)}

//if(check2.rawValue == "Yes")

//{k = k.concat(array2)}

for 
(i=0; i<array1.length; i++){
if (i>0) {Row01.InstanceManager.addInstance(1)}
xfa.resolveNode("Table.Row01["+i+"].col2").rawValue = array1[i];
}

Any help would be greatly appreciated.

I tested this solution, it works :)
- the arrays will add up in the same order each time though, if you want it in the order you clicked the checkboxes it might get more complicated but you didn't specifically asked for that so I hope it's enough to make you understand how it can work:

Before you start:

  • Make sure you allow the Row to create more instances (checkboxes on the bottom) 在此处输入图片说明
  • Make sure you know what the "on"-Value of your checkboxes is (in my case 1) 在此处输入图片说明
  • Create a Scriptobject for you code (optional)
    在此处输入图片说明

Inside each checkbox click-Event write logic.populateCol2(); :

 Formular1.#subform[0].Kontrollkästchen1[0]::click - (JavaScript, client)
logic.populateCol2();

And in the logic Scriptobject write this:

function populateCol2() {
    var array1 = ["one", "two", "Three", "Four", "Five"];
    var array2 = ["this", "that", "and this"];
    var array3 = ["another one"];
    var array4 = ["Finally this"];

    var cb1 = Kontrollkästchen1;
    var cb2 = xfa.resolveNode("Kontrollkästchen1[1]");
    var cb3 = xfa.resolveNode("Kontrollkästchen1[3]");
    var cb4 = xfa.resolveNode("Kontrollkästchen1[2]");

    //Put in all your checkboxes here and corresponding array
    var chbxs = [
        [cb1, array1],
        [cb2, array2],
        [cb3, array3],
        [cb4, array4]
    ];

    var allValues = [];
    for (var x = 0; x < chbxs.length; x++) {
        var currentCbx = chbxs[x][0];
        var currentArr = chbxs[x][1];
        //Or ==="Yes" in your case
        if (currentCbx.rawValue === 1) {
            allValues = allValues.concat(currentArr);
        }
    }

    //Set it back so it won't add up rows to infinity
    Table.Row01.instanceManager.setInstances(1);
    Table.Row01.col2.rawValue = "";

    for (var i = 0; i < allValues.length; i++) {
        if (i > 0) {
            Table.Row01.instanceManager.addInstance(true);
        }
        xfa.resolveNode("Table.Row01[" + i + "].col2").rawValue = allValues[i];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM