Adobe JavaScript用数组更改数组中的一堆字段值

问题描述

我有一个带有多个字段的PDF,用于开票。这些字段是计算员工薪资的发票的一部分。有了这个PDF,我想实现一个“历史”,以便他们可以回头查看以前的工作。我的代码可以工作,但是使用for循环很慢。我想知道是否有更快的处理方法

我有两个按钮,“ PrevIoUsJob”和“ NextJob”,并且有两组字段。一组存储字段名称,另一组存储相应的数据(字段名称是“ FieldName ##”,实际数据部分是“ History ##”)。每个字段都用逗号(“,”)分隔。下面是我在工作之间来回移动的代码

this.delay = true
this.getField ( "PrevIoUsJob" ).readonly = true // This is so they don't click the button's twice
this.getField ( "NextJob" ).readonly = true     // This is so they don't click the button's twice

if ( event.target.name == "NextJob" ){
    var AddOrSub = -1                           // Determines which button the user pressed
} else {
    var AddOrSub = 1                            // Determines which button the user pressed
}

// CurrentHistory tells me which job their current viewing
var CurrentHistory = this.getField ( "CurrentHistory" ).value + AddOrSub

if ( this.getField ( "FieldName" + CurrentHistory ).value ){
    // I have [48] Fields allocated for data
    if ( CurrentHistory > 0 && CurrentHistory <= 24 ){
        
        // This separates the fieldname and history by "," into arrays
        var SplitFieldName = this.getField ( "FieldName" + CurrentHistory ).value.split(",")
        var SplitHistory = this.getField ( "History" + CurrentHistory ).value.split(",")
        
        // ******************************************************************
        //      This is the For Loop that runs SLOW
        // ******************************************************************
        if (SplitFieldName != "" && SplitHistory != "" ) {
            for (i = 0; i < SplitFieldName.length; i++) {
                if (this.getField ( SplitFieldName[i] ).value != SplitHistory[i] ) {
                    //Go through each fieldname and changes the value with the History
                    this.getField ( SplitFieldName[i] ).value = SplitHistory[i]
                }
            }
            this.getField ( "CurrentHistory" ).value = CurrentHistory
        } else {
            app.alert("There's no further history you can review")
        }
    } else if ( CurrentHistory == 0 ) {
        // ******************************************************************
        // On new jobs it resets the fields but it's Much faster vs for loop
        // ******************************************************************
        // This get's an array of the fieldnames and resets it
        var SplitFieldName = this.getField ( "FieldName1" ).value.split(",");
        this.resetForm(SplitFieldName);
        this.getField ( "CurrentHistory" ).value = CurrentHistory
    }
}
this.getField ( "PrevIoUsJob" ).readonly = false
this.getField ( "NextJob" ).readonly = false
this.delay = false

最后,我想加快更改Adobe PDF中多个字段的值的过程。我愿意接受任何建议。

预先感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)