首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getValue()表示SelectField

getValue()表示SelectField
EN

Stack Overflow用户
提问于 2017-07-06 03:04:01
回答 2查看 225关注 0票数 0

我只想做的就是获取公司的名称并将其保存到数据库中

我试着处理文本,并试图使用下面的代码来获取

sport: this.refs.company.getValue(),和它工作得很完美。

然后我决定为公司使用材料UI中的SelectField

而不是获取数据。

代码语言:javascript
复制
constructor(props) {
super(props);
this.state = {
  value: 1,
};
}

submitResume(event) {
    event.preventDefault();
    console.log(this.state.company.getValue({value}));

CreatePost.insert({
        company: this.refs.company.getValue(),

        employee: this.refs.employee.getValue(),

    });
    console.log("Employee Profile Submitted!");
}


handleNameChange = (event, index, value) => this.setState({value});

    <form onSubmit={this.submitResume.bind(this)}>

          <SelectField
                    floatingLabelText="Company Name"
                    className="validate"
                    ref="company"
                    id="company"
                    floatingLabelStyle={{fontSize:20}}
                    fullWidth={true}
                    value={this.state.value}
                    onChange={this.handleNameChange}
                  >
                    <MenuItem value={1} primaryText="Google" />
                    <MenuItem value={2} primaryText="Facebook" />
                    <MenuItem value={3} primaryText="Amazon" />
                    <MenuItem value={4} primaryText="Nest" />
                    <MenuItem value={5} primaryText="Microsoft" />
            </SelectField>

            <TextField
                className="validate"
                type="text"
                ref="employee"
                id="employee"
                hintText="Enter Full Name"
                floatingLabelStyle={{fontSize:20}}
                floatingLabelText="Employee Name"
                multiLine={true}
                rows={1}
                fullWidth={true}
            />

它对TextField很好,但对SelectField却不起作用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-06 04:35:57

现在看到这个更新的值,您将在参数valueindexevent中获得值。

代码语言:javascript
复制
constructor(props) {
super(props);
this.state = {
  value: 1,
};
}

submitResume(event) {
    event.preventDefault();
    console.log(this.state.company.getValue({value}));

CreatePost.insert({
        company: this.refs.company.getValue(),

        employee: this.refs.employee.getValue(),

    });
    console.log("Employee Profile Submitted!");
}


handleNameChange(event, index, value) {
  console.log(event);
  console.log(index);
  console.log(value);
  this.setState({value});
}

    <form onSubmit={this.submitResume.bind(this)}>

          <SelectField
                    floatingLabelText="Company Name"
                    className="validate"
                    ref="company"
                    id="company"
                    floatingLabelStyle={{fontSize:20}}
                    fullWidth={true}
                    value={this.state.value}
                    onChange={this.handleNameChange}
                  >
                    <MenuItem value={"Google"} primaryText="Google" />
                    <MenuItem value={"Facebook"} primaryText="Facebook" />
                    <MenuItem value={"Amazon"} primaryText="Amazon" />
                    <MenuItem value={"Nest"} primaryText="Nest" />
                    <MenuItem value={"Microsoft"} primaryText="Microsoft" />
            </SelectField>

            <TextField
                className="validate"
                type="text"
                ref="employee"
                id="employee"
                hintText="Enter Full Name"
                floatingLabelStyle={{fontSize:20}}
                floatingLabelText="Employee Name"
                multiLine={true}
                rows={1}
                fullWidth={true}
            />
票数 1
EN

Stack Overflow用户

发布于 2017-07-11 20:25:49

我所需要做的就是传递文本值而不是数字

代码语言:javascript
复制
<MenuItem value={"Google"}    primaryText="Google"    />
<MenuItem value={"Facebook"}  primaryText="Facebook"  />
<MenuItem value={"Amazon"}    primaryText="Amazon"    />
<MenuItem value={"Nest"}      primaryText="Nest"      />
<MenuItem value={"Microsoft"} primaryText="Microsoft" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44939120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档