我想将用户输入的ImageTag的值以及从下拉菜单(material-ui的selectField)中选择的locationValue传递给服务器插座。React JS Uncaught ReferenceError:未定义locationValue(变量)
这里是我的代码: -
var BaseImageDetails = React.createClass({
getInitialState:function(){
return{
imageTag: '',
locationValue: ''
};
},
contextTypes: {
socket: React.PropTypes.object.isRequired
},
handleImageChange:function(event){
this.setState({imageTag: event.target.value});
console.log(imageTag);
},
handleLocationChange:function(event){
this.setState({locationValue: event.target.value});
console.log(locationValue);
},
clickedBase: function(e){
e.preventDefault();
this.context.socket.emit("baseImageSubmit",{imageTag},{locationValue});
},
render(){
console.log("wwooowwowow" , this.props.locationDetails);
var locationItems = this.props.locationDetails.map(function(locationItem){
return <MenuItem value = {locationItem} primaryText = {locationItem} />
}.bind(this));
console.log("locationItems------------",locationItems);
return(
<div>
<Card>
<CardHeader
title="Please provide the following details ? "
actAsExpander={true}
showExpandableButton={true}
/>
<form onSubmit = {this.clickedBase} >
<TextField hintText="Image Tag"
floatingLabelText="Image Tag"
value = {this.state.imageTag} onChange = {this.handleImageChange}/>
<Divider />
<SelectField
fullWidth={true}
hintText="Select the location of your base-image Dockerfile"
onChange = {this.handleLocationChange}
value = {this.state.locationValue}
maxHeight={200}>
{locationItems}
</SelectField>
<Divider />
<RaisedButton label="Secondary" primary={true}
label="Build" secondary={true}
type = "submit" />
</form>
</Card>
</div>
);
}
});
不过,虽然安慰它打印 “未捕获的ReferenceError:locationValue没有定义” 既为locationValue和imageTag。 你们能帮助我在哪里,我做错了....
看来你行'this.context.socket.emit( “baseImageSubmit”,{imageTag},{locationValue });'应该改为'this.context.socket.emit(“baseImageSubmit”,{imageTag:this.state.imageTag},{locationValue:this.state.locationValue});' – Joy
Yeah Man !!!!谢谢一吨 –