2016-09-20 19 views
0

ユーザーが入力したImageTagの値とドロップダウンメニュー(material-uiのselectField)から選択されたlocationValueを経由してサーバーに渡そうとしています。ソケット。React JS Uncaught ReferenceError:locationValue(variable)が定義されていません

は、ここに私のコードです: -

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のための両方。私が間違っているのどこ は、あなたたちは、あなたが{imageTag}を書くとき

+0

'this.context.socket.emit( "baseImageSubmit"、{imageTag}、{locationValueあなたのラインに思えるを使用しようとしている場合を意味します}); 'は' this.context.socket.emit( "baseImageSubmit"、{imageTag:this.state.imageTag}、{locationValue:this.state.locationValue})に変更する必要があります; ' – Joy

+0

Yeah Man !!!!ありがとうございました –

答えて

0

が、それは{imageTag: imageTag}を書くのと同じです....私を助けることができ、あなたのスコープにimageTagと呼ばれるローカル変数はありません。

おそらく

this.context.socket.emit("baseImageSubmit",{ 
    imageTag: this.props.imageTag 
},{ 
    locationValue: this.props.locationValue 
}); 

それとも、destructuring assignments

const {imageTag, locationValue} = this.props; 
this.context.socket.emit("baseImageSubmit",{imageTag},{locationValue}); 
+0

ええ、私はそれがあなたが上記のように1つであったはずの間違いを作った!!それでも...たくさんありがとうございます –

+0

@ParamveerSinghそれでも何ですか? –

+0

あなたが指摘した間違いは、同じスコープにimageTagというローカル変数を付けずに{imageTag}を書いたときに私が気づいたことです。このエラーが発生した理由は...ありがとうございます。 –

関連する問題