Acrobat 中的 Javascript - 无法将值传递出对话框

    我在使用 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"

                                },

                    ]

                }

            ]

        }

    }

}


胡说叔叔
浏览 165回答 1
1回答

慕神8447489

看看我为你写的新提交函数。列表项存储为列表,其中具有正索引值的项是选定项。然后,您可以访问选定的值。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); }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript