【发布时间】:2015-06-28 22:39:48
【问题描述】:
在过去的几个小时里,我一直在努力尝试使用 ReactJS 和语义 UI 来让一个简单的下拉更改事件起作用。 From my understanding, the onChange property of the element is supposed to fire the event handler it is bound to when a different option is selected.这是我的代码:
var DictionarySelector = React.createClass({
getInitialState: function() {
return {value: ""}
},
handleChange: function(e) {
this.setState({value: e.target.value});
console.log('Dropdown changed');
return;
},
render: function() {
return (
<div className="ui form" style={{marginTop:'55px'}}>
<div className="field">
<select className="ui dropdown" onChange={this.handleChange} value={this.state.value}>
<option value="">Select Dictionary</option>
<option value="1">Dictionary 1</option>
<option value="2">Dictionary 2</option>
</select>
</div>
</div>
);
}
});
一切似乎都很好,我对此进行了大量研究,但是当下拉菜单中的选项发生变化时,什么也没有发生。永远不会调用 handleChange 函数。有人有什么建议吗?
谢谢!
【问题讨论】:
-
我不认为这是原因,但您的样式属性缺少左大括号:
style="marginTop:'55px'}}>
标签: javascript reactjs semantic-ui