我正在尝试构建一个包含基于状态的不同组件的动态div。我有我的自定义组件活动,稳定和形式。Reactjs窗体onSubmit无法正常工作
render: function() {
var components = [];
if (this.state.isActive) {
components.push(React.DOM.Active));
}
if (this.state.isStable) {
components.push(React.DOM.Stable({}));
}
if (this.state.visible) {
components.push(React.DOM.Form({}));
}
return React.DOM.div({}, components);
}
的表单组件是一个简单的形式,其具有
handleSubmit(e) {
e.preventDefault();
console.log('Submitted');
}
render: function() {
return React.DOM.form({onSubmit: this.handleSubmit}, [React.DOM.button({},'Submit')]);
}
的handleSubmit方法不会被调用。但如果我将代码更改为:
render: function() {
var components = [];
components.push(React.DOM.Form({}));
return React.DOM.div({}, components);
}
有谁知道问题可能来自哪里?
当您更改代码时会发生什么?你没有指定。 – SevenBits
糟糕!我忘了指定它!它在控制台中写入“已提交”,并且阻止了该事件的默认行为。 –