目前,我正在主Runner脚本中的python文件中导入每个类。目的是基于给定的字符串实例化与给定的字符串具有相同名称的类。
例如:
如果有一个名为“测试”的类:
class Test():
Run Code Online (Sandbox Code Playgroud)
如果字符串为“ Test”,它将调用该类。
我有以下代码:
export default class Contact extends React.Component {
constructor(props) {
super(props);
this.state = {
password: '',
redirect: false,
username: ''
};
this.onUsernameChange = this.onUsernameChange.bind(this);
this.onPasswordChange = this.onPasswordChange.bind(this);
}
onUsernameChange(event) {
this.setState({ username: event.target.value });
}
onPasswordChange(event) {
this.setState({ password: event.target.value });
}
handleSubmit(event) {
event.preventDefault();
alert('A name was submitted: ' + this.state.username);
//sessionStorage.setItem('username', this.state.username);
}
render() {
return (
<div>
<form className="form-signin" onSubmit={this.handleSubmit}>
<input type="text" value={this.username} onChange={this.onUsernameChange} />
<input type="password" value={this.password} onChange={this.onPasswordChange} />
<input type="submit" value="Submit" />
</form>
</div>
); …Run Code Online (Sandbox Code Playgroud)