• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Accessing nested objects and arrays for SetItems method

New Here ,
Feb 17, 2020 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

Views

649

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
community guidelines
Community Expert ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Feb 17, 2020 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. 

Votes

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
community guidelines
Community Expert ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

LATEST

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);

Votes

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
community guidelines