Accessing nested objects and arrays for SetItems method

New Here ,
Feb 17, 2020

Copy link to clipboard

Copied

Hi,

I have a dropdown menu ("Dropdown1"), that I need to populate with options from the object I have defined below. How would I go about populating Dropdown1 with the names (Name1, Name2, & Name3) from the Class1 array?

var oClassList = 
{
    Class1:
    [
        {name: "Name1", company: "Company1", instructor: "Instructor1"},
        {name: "Name2", company: "Company2", instructor: "Instructor1"},
        {name: "Name3", company: "Company3", instructor: "Instructor1"}
    ],
    Class2:
    [
        {name: "Name1", company: "Company1", instructor: "Instructor2"},
        {name: "Name2", company: "Company2", instructor: "Instructor2"},
        {name: "Name3", company: "Company3", instructor: "Instructor2"}
    ],
    Class3:
    [
        {name: "Name1", company: "Company1", instructor: "Instructor3"},
        {name: "Name2", company: "Company2", instructor: "Instructor3"},
        {name: "Name3", company: "Company3", instructor: "Instructor3"}
    ]
};

 I tried the following code using the setItems method, but I couldn't get it to work:

this.getField("Dropdown1").setItems(oClassList.Class1.name);

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

159

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Accessing nested objects and arrays for SetItems method

New Here ,
Feb 17, 2020

Copy link to clipboard

Copied

Hi,

I have a dropdown menu ("Dropdown1"), that I need to populate with options from the object I have defined below. How would I go about populating Dropdown1 with the names (Name1, Name2, & Name3) from the Class1 array?

var oClassList = 
{
    Class1:
    [
        {name: "Name1", company: "Company1", instructor: "Instructor1"},
        {name: "Name2", company: "Company2", instructor: "Instructor1"},
        {name: "Name3", company: "Company3", instructor: "Instructor1"}
    ],
    Class2:
    [
        {name: "Name1", company: "Company1", instructor: "Instructor2"},
        {name: "Name2", company: "Company2", instructor: "Instructor2"},
        {name: "Name3", company: "Company3", instructor: "Instructor2"}
    ],
    Class3:
    [
        {name: "Name1", company: "Company1", instructor: "Instructor3"},
        {name: "Name2", company: "Company2", instructor: "Instructor3"},
        {name: "Name3", company: "Company3", instructor: "Instructor3"}
    ]
};

 I tried the following code using the setItems method, but I couldn't get it to work:

this.getField("Dropdown1").setItems(oClassList.Class1.name);

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

160

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 17, 2020 0
Adobe Community Professional ,
Feb 17, 2020

Copy link to clipboard

Copied

It must be an array. Read the documentation of setItems.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2020 1
Adobe Community Professional ,
Feb 17, 2020

Copy link to clipboard

Copied

You would have to create a temp array variable that holds the names you want to assign to the dropdown. I would write a function that takes as arguments the class name and the class structure and then extracts the relevant names and returns them in an array variable that you can then use in the setItems() method. There is no direct way go go from the data structure you have to setting the dropdown values. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2020 1
try67 LATEST
Most Valuable Participant ,
Feb 17, 2020

Copy link to clipboard

Copied

You can do it like this:

 

var names = [];
for (var i in oClassList.Class1) names.push(oClassList.Class1[i].name);
this.getField("Dropdown1").setItems(names);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 17, 2020 1