Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试根据所选选项显示字段_Javascript_Node.js_Reactjs_Material Ui - Fatal编程技术网

Javascript 尝试根据所选选项显示字段

Javascript 尝试根据所选选项显示字段,javascript,node.js,reactjs,material-ui,Javascript,Node.js,Reactjs,Material Ui,我有团队和竞赛的注册部分,但我尝试做的是当用户选择竞赛时,我尝试显示促销代码字段,该字段仅在选择竞赛时显示。如果选择了团队,则不会显示促销字段,提前感谢hep React.Component { constructor(props) { super(props); this.state = {name: '', email: '', password: ''}; } ha

我有团队和竞赛的注册部分,但我尝试做的是当用户选择竞赛时,我尝试显示促销代码字段,该字段仅在选择竞赛时显示。如果选择了团队,则不会显示促销字段,提前感谢hep

        React.Component {
          constructor(props) {
            super(props);
            this.state = {name: '', email: '', password: ''};
          }

          handleChange(event) {
            this.setState({ [event.target.name]: event.target.value });
          }

          handleSelect(event, index, value) {
            this.setState({type: value});
          }

          handleSignup(event) {
            event.preventDefault();
            this.props.dispatch(signup(this.state.name, this.state.email, this.state.password, this.state.promo, this.state.type));
          }



          render() {
            return (
              <div className="login">
                <div className="panel">
                  <div className="body">
                    <legend>Create an account</legend>
                    <SelectField
                      floatingLabelText="User or Admin"
                      value={this.state.type}
                      name="type" id="type"
                      onChange={this.handleSelect.bind(this)}
                    >
                      <MenuItem value={"USER"} primaryText="User" />
                      <MenuItem value={"ADMIN"} primaryText="Admin" />
                    </SelectField>

                    <TextField
                      hintText="Promo Code"
                      name="promo" id="promo" autoFocus
                      value={this.state.code} onChange={this.handleChange.bind(this)}
                      floatingLabelText="Promo Code"
                    />
React.Component{
建造师(道具){
超级(道具);
this.state={name:'',电子邮件:'',密码:'};
}
手变(活动){
this.setState({[event.target.name]:event.target.value});
}
handleSelect(事件、索引、值){
this.setState({type:value});
}
handleSignup(事件){
event.preventDefault();
this.props.dispatch(注册(this.state.name,this.state.email,this.state.password,this.state.promo,this.state.type));
}
render(){
返回(
创建帐户
仅当州的类型包含“竞争”时,才有条件地呈现文本字段“促销代码”:

{condition?:null}
包围字段:

 {this.state.type === 'COMPETITION'
      ? <TextField
             hintText="Promo Code"
             name="promo" id="promo" autoFocus
             value={this.state.code} onChange={this.handleChange.bind(this)}
             floatingLabelText="Promo Code"
        />
      : null}
{this.state.type==='COMPETITION'
? 
:null}
仅当州的类型包含“竞争”时,才有条件地呈现文本字段“促销代码”:

{condition?:null}
包围字段:

 {this.state.type === 'COMPETITION'
      ? <TextField
             hintText="Promo Code"
             name="promo" id="promo" autoFocus
             value={this.state.code} onChange={this.handleChange.bind(this)}
             floatingLabelText="Promo Code"
        />
      : null}
{this.state.type==='COMPETITION'
? 
:null}

您是否希望您编写的代码显示/隐藏促销字段?或者您询问如何编写代码?您是否希望您编写的代码显示/隐藏促销字段?或者您询问如何编写代码?我也在尝试验证促销代码,我想硬编码促销代码,用户必须输入该代码代码和它必须验证,有什么想法吗?我正在尝试使用onBlur添加一个函数来检查输入是否匹配所需的单词。但需要一些帮助这已经是下一个问题了。请在StackOverflow上单独提问。你能得到“基于所选选项显示字段”吗按照我在回答中的建议运行?正如你所说,我已经创建了另一个问题,如果你能帮助我,那将非常好,也是的,非常感谢你的回答。我也会研究你的其他问题。我也在尝试验证促销代码,我想硬编码促销代码,用户必须输入该代码d它必须验证,有什么想法吗?我正在尝试使用onBlur添加一个函数,检查输入是否与所需的单词匹配。但需要一些帮助这已经是下一个问题了。请在StackOverflow的单独问题中询问这些问题。你能得到“基于所选选项显示字段”吗按照我在回答中的建议跑步?正如你所说,我已经提出了另一个问题,如果你能帮助我,那将是非常好的,而且是的,非常感谢你的回答。我也会研究你的另一个问题。