Reactjs 为什么我的React-onChange事件处理程序没有启动?
不明白为什么我的React事件处理程序似乎没有启动(console.log没有输出)。我确实有CertTypeSelect的组件类。看来处理者应该开火了。我需要在这里输入更多的非代码以便SO的系统允许我保存我的编辑,甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码Reactjs 为什么我的React-onChange事件处理程序没有启动?,reactjs,Reactjs,不明白为什么我的React事件处理程序似乎没有启动(console.log没有输出)。我确实有CertTypeSelect的组件类。看来处理者应该开火了。我需要在这里输入更多的非代码以便SO的系统允许我保存我的编辑,甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码甚至更多的非代码 class CertTypeSelect extends React.Component { construct
class CertTypeSelect extends React.Component {
constructor(props) {
super(); // super(props);
this.state = {
}; // this.state
} // constructor
render() {
const certTypeOptions = []; //
certTypeOptions.push(<CertSelectOption optionText="Select type"/>); //
storeData.forEach((storeDatum) => {
certTypeOptions.push(
<CertSelectOption optionText={storeDatum.catTitle}/>
); // push
}); // forEach
return (
<div className="form-group third"><p><strong>Type</strong></p>
<label className="select">
<select name="govcapost-cert-type" id="govcapost-cert-type">{certTypeOptions}</select>
</label></div>
); // return
} // render
} // CertTypeSelect
// top-most "app" component:
class CertSelectionControls extends React.Component {
constructor(props) {
super(props); //
this.state = {
type: 'Select type',
level: 'Select level',
replacement: false
}; // this.state
// all componenent methods must be bound during the constructor -
this.setType = this.setType.bind(this); //
// log(this.state) // yes works
} // constructor
setType(event) {
console.log('setType')
// this.setState({type:event.target.value}); // setState
} // setType
render() {
return (
<span><div className="group"><CertTypeSelect value={this.state.type} onChange={this.setType} /></div><CertPricePreview /><CertContinueButton /></span>
); // return
} // render
} // CertSelectionControls
class CertTypeSelect扩展了React.Component{
建造师(道具){
super();//super(道具);
此.state={
}这个州
}//构造函数
render(){
常量certTypeOptions=[];//
certTypeOptions.push();//
storeData.forEach((storeDatum)=>{
certTypeOptions.push(
);//推
});forEach
返回(
类型
{certTypeOptions}
);//返回
}//渲染
}//CertTypeSelect
//最顶级的“应用程序”组件:
类CertSelectionControls扩展了React.Component{
建造师(道具){
超级(道具);//
此.state={
类型:“选择类型”,
级别:“选择级别”,
替换:错误
}这个州
//在构造过程中,必须绑定所有组件方法-
this.setType=this.setType.bind(this)//
//log(this.state)//yes有效
}//构造函数
设置类型(事件){
console.log('setType')
//this.setState({type:event.target.value});//setState
}//集合类型
render(){
返回(
);//返回
}//渲染
}//CertSelectionControls
由于CertTypeSelect是一个自定义组件,而不是通用jsx标记,因此onChange作为一个道具传递给CertTypeSelect
您需要在CertTypeSelect内调用此onChange函数
onChange是否也是CertTypeSelect中元素的有效属性?如果没有,则不会有事件参数传递给您的函数。因为CertTypeSelect是一个自定义组件,而不是通用jsx标记,所以onChange作为道具传递给CertTypeSelect 您需要在CertTypeSelect内调用此onChange函数
onChange是否也是CertTypeSelect中元素的有效属性?如果没有,则不会有事件参数传递给您的函数。您可以提供CertTypeSelect的代码吗?请共享CertTypeSelect组件的代码,因为您将setType作为onChange prop传递给CertTypeSelect,因此在组件中您应该调用它。您将事件附加到组件,而不是jsx标记。如果您想保留该属性,您需要在该组件内触发事件。您可以提供CertTypeSelect的代码吗?请共享CertTypeSelect组件的代码,因为您将setType作为onChange prop传递给CertTypeSelect,因此在组件中您应该调用它。您将事件附加到组件,而不是jsx标记。如果您想保持该状态,则需要在该组件内触发事件。