I'm iterating through a dict and displaying the keys in a react-bootstrap dropdown menu. This is my React dropdown Component,
class Dropdown extends React.Component
{
constructor(props)
{
super(props);
this.onTargetSelect = this.onTargetSelect.bind(this);
}
onTargetSelect(target)
{
console.log("Outputting from here: ", target);
document.getElementById("dropdown-title").textContent(target);
this.props.passTargetToParent(target);
}
render()
{
return(
<SplitButton title="Select Target" id="dropdown-target">
{Object.keys(dict).map(key => <MenuItem key={dict[key]}
href={`#${dict[key]}`}
onSelect={this.onTargetSelect(dict[key])}>{key}</MenuItem>)}
</SplitButton>);
}
}
There are two things that I'm trying to do here, which are proving difficult because of my limited knowledge of Javascript.
This displays all the values associated with the respective keys on load. That's not the behavior I want. I only want to console log the selected Item in the dropdown.
Second I want to change the title displayed currently as
Select Targetto the selected item in the dropdown.