简体   繁体   English

在LiveCycle Designer中从数组填充表

[英]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. 我对Java还是比较陌生,并且已经开始了解一些用于在LiveCycle Designer ES4中创建表单的基本语言和功能。

I have 4 check boxes (say "check1", check 2...), and 4 predefined arrays ( "array1", array2....). 我有4个复选框(例如“ check1”,check 2 ...)和4个预定义的数组(“ array1”,array2 ....)。 I have a table below all these with 3 columns, (col1, col2, col3). 我在所有这些下面都有一个表,其中有3列(col1,col2,col3)。

What I want to do is this: 我想做的是这样的:

  • When I check "check1", I want to populate col2 of the table with array1. 当我检查“ check1”时,我想用array1填充表的col2。
  • 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) 确保您知道复选框的“启用”值是多少(在我的情况下为1) 在此处输入图片说明
  • Create a Scriptobject for you code (optional) 为您的代码创建一个脚本对象(可选)
    在此处输入图片说明

Inside each checkbox click-Event write logic.populateCol2(); 在每个复选框内,单击事件均写入logic.populateCol2(); :

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

And in the logic Scriptobject write this: 然后在logic Scriptobject中编写以下代码:

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];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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