1

Can I pass object of data in select option ?

I'm displaying name in select option & I'm using ID in value.

After some option is selected, I want to display the selected option. Since the value is ID, I can't display name.

How can I solve this?

This is my code:

{
 Makes.hasData ?
   (_.map(Makes.data.data, (make, index) => {
       return (
             <option key={index} value={make.id}> {make.make}</option>
         );
     }))
    : ''
}

Thank You

1 Answer 1

1

On your select option you will have onChange in that you can search in the array for the obejct with a given id using lodash's find method

handleChange(e) {
    var id=e.target.value
    var value = _.result(_.find(Makes.data.data, function(obj) {
         return obj.id=== id;
     }), 'make');
    console.log(value)
}
Sign up to request clarification or add additional context in comments.

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.