Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
How can I pass an array of values in the Ant Design cascader?

I am using Ant Design to create a cascading dropdown. Instead of hard coding the values, how can I populate them from an array? Right now, the dropdown is showing the value array as one long list, instead of separating it into different options. Here is my code so far:

var valueArray = ["a", "b", "c"];
var childrenArray = ["d", "e", "f"];
var val;
var child; 

for(var i=0; i<valueArray.length; i++){
    val = valueArray[i];
    child = chilrenArray[i]
}
const options = [
  {
    value: val,
    label: val,
    children: [
      {
        value: child,
        label: child,
      }
     ]
   }
];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Give this a try:

var valueArray = ["a", "b", "c"];
var childrenArray = ["d", "e", "f"];

const options = valueArray.map(v => {
  const item = {
    value: v,
    label: v,
  };
  if (v === "a") {
    // add the children
    item.children = childrenArray.map(c => ({
      value: c,
      label: c
    }));
  }
  return item;
});

console.log(options);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!