0

If I have the following json data, How can I populate Bird_Name in the dropdown list with semantic?

Note: I'm using react with es6.

var birds = [
            {
                "ID": "001",
                "Bird_Name": "Eurasian Collared-Dove"
            },
            {
                "ID": "002",
                "Bird_Name": "Bald Eagle"
            },
            {
                "ID": "003",
                "Bird_Name": "Cooper's Hawk"
            },
        ];

Semantic dropdown

            <Container>
                <Divider hidden />
                <Dropdown 
                placeholder='Select...' 
                selection
                search
                options={options}
                />
            </Container>

2 Answers 2

2

One way you could do this is by mapping the Bird_Name fields as text, and assuming you want the ID as the value:

const options = birds.map(({ ID, Bird_Name }) => ({ value: ID, text: Bird_Name }))

Now you can pass the options into your Dropdown component

You can check out the codepen here: https://codepen.io/poda/pen/BYwZNB

Sign up to request clarification or add additional context in comments.

Comments

0

You have two ways:

  1. Change your data to be like the schema that dropdown accept

  2. You can map your data to the dropdown.item and put it in the dropdown as a variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.