簡體   English   中英

Acrobat 中的 Javascript - 無法將值傳遞出對話框

[英]Javascript in Acrobat - Can't pass values out of dialog box

我在使用 Adobe Acrobat 中的自定義對話框時遇到了困難。

我的目標是在您單擊頂部工具欄中的按鈕時出現一個對話框。 該對話框將包含一個可編輯的文本字段和一個 list_box。 輸入文本后,從列表框中進行選擇,然后單擊確定,這些值將傳遞到 PDF 文檔上的文本字段。 現在我讓他們的值返回到控制台。

每次我嘗試運行代碼時,兩個變量(一個用於文本字段條目,一個用於列表框選擇)都返回未定義。 我對 Acrobat 中的 javascript 非常陌生,所以這個項目就像一個由互聯網上不同代碼片段組成的科學怪人一樣慢慢聚集在一起,哈哈。

任何見解將不勝感激!

var timeDialog = {
    initialize: function(dialog) {this.loadDefaults(dialog);},
        commit: function(dialog) { 
            var timeEntry = dialog.store()["tetb"]
            var techEntry = dialog.store()["tnlb"]
          },
        loadDefaults: function (dialog) {
            dialog.load({
                "tnlb":
                {
                    "Jimmy John": +2,
                    "Papa John": +1,
                    "Great Gatsby": +0
                }
            })
        },
        description: 
        {
            name: "Time Dedicated", 
            elements: 
            [
                { 
                    type: "view",  
                    elements: 
                    [
                        {
                            type: "cluster",
                            elements:
                            [
                                {
                                    name: "Time spent on Request (minutes):", 
                                    type: "static_text"
                                },
                                {
                                    type: "edit_text",
                                    item_id: "tetb",
                                    char_width: 5
                                },
                                {
                                    name: "Technician:", 
                                    type: "static_text"
                                },
                                {
                                    item_id: "tnlb", 
                                    type: "list_box",
                                    width: 200,
                                    height: 60
                                }
                            ]
                        },
                        {
                            type: "ok_cancel"
                        }
                    ]
                }
            ]
        }
    }

if( "ok" == app.execDialog(timeDialog)) { 
    var today = new Date();
    var time = today.getHours() + "." + today.getMinutes() + "." + today.getSeconds();
    var TEMP_FIELD_NAME = timeDialog.timeEntry
    var textValue = timeDialog.techEntry;
    console.println(TEMP_FIELD_NAME); 
    console.println(textValue); 
}

謝謝!

看看我為你寫的新提交 function。 列表項存儲為列表,其中具有正索引值的項是選定項。 然后,您可以訪問選定的值。

var timeDialog = {
    initialize: function (dialog) { this.loadDefaults(dialog); },
    commit: function (dialog) {
        this.timeEntry = dialog.store()["tetb"];
        var items = dialog.store()["tnlb"]
        for (var item in items) {
            if (items[item] > 0) {
                this.techEntry = item;
                break;
            }
        }
    },
    loadDefaults: function (dialog) {
        dialog.load({
            "tnlb":
            {
                "Jimmy John": +2,
                "Papa John": +1,
                "Great Gatsby": +0
            }
        })
    },
    description:
    {
        name: "Time Dedicated",
        elements:
            [
                {
                    type: "view",
                    elements:
                        [
                            {
                                type: "cluster",
                                elements:
                                    [
                                        {
                                            name: "Time spent on Request (minutes):",
                                            type: "static_text"
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "tetb",
                                            char_width: 5
                                        },
                                        {
                                            name: "Technician:",
                                            type: "static_text"
                                        },
                                        {
                                            item_id: "tnlb",
                                            type: "list_box",
                                            width: 200,
                                            height: 60
                                        }
                                    ]
                            },
                            {
                                type: "ok_cancel"
                            }
                        ]
                }
            ]
    }
}

if ("ok" == app.execDialog(timeDialog)) {
    console.println(timeDialog.timeEntry);
    console.println(timeDialog.techEntry); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM