다른 드롭 다운의 값에 따라 드롭 다운의 가시성을 토글하려고합니다. 따라서 첫 번째 옵션을 선택하면 두 번째 드롭 다운이 아래에 표시되고 해당 옵션을 더 이상 선택하지 않으면 아래 드롭 다운이 사라집니다.드롭 다운 값에 따라 가시성 토글 ReactJS
나는 아직도 배우고 있기 때문에 저와 함께하시기 바랍니다. 어떤 조언이나 도움을 주시면 감사하겠습니다! 여기에 지금까지 무엇을 가지고 :
const firstOptions = [
{ key: 0, value: 'default', text: '--Select an Option--' },
{ key: 1, value: 'option1', text: 'option1 - when I am selected another shall appear' },
{ key: 2, value: 'option2', text: 'option2' },
{ key: 3, value: 'option3', text: 'option3' },
];
const secondOptions = [
{ key: 0, value: 'default', text: '--Select an Option--' },
{ key: 1, value: 'option1', text: 'option1' },
{ key: 2, value: 'option2', text: 'option2' },
];
class DropdownToggle extends Component {
constructor(props) {
super(props);
this.state = {
selectedValue: 'default',
};
}
handleChange = (e) => {
this.setState({ selectedValue: e.target.value });
}
render() {
const message = 'You selected ' + this.state.selectedValue;
return (
<div style={{ marginTop: '50px', marginLeft: '50px' }}>
<Dropdown
options={firstOptions}
selection
value={this.state.selectedValue}
onChange={this.handleChange}
/>
<div style={{ marginTop: '50px' }}>
<Dropdown
options={secondOptions}
selection
/>
</div>
<p>{message}</p>
</div>
);
}
}
100 % 작동하지 않습니다. 나는 handleChange 함수에서 뭔가를 놓치고 있기 때문에 options 배열에서 값을 가져 오는 것을 알고 있습니까? – StuffedPoblano
handleChange에서'console.log (e.target.value)'를 실행하고 올바른 값인 – bennygenel
을 주는지 확인해 보면'undefined'가됩니다. – StuffedPoblano