2016-01-31 11 views
6

Attualmente ho questa semplice app di reazione e non riesco a far scattare questi eventi di modifica per la vita di me.L'input di reazione su Change non viene generato

var BlogForm = React.createClass({ 
getInitialState: function() { 
    return { 
     title: '', 
     content: '' 
    }; 
}, 
changeTitle: function(event) { 

    var text = event.target.value; 

    console.log(text); 

    this.setState({ 
     title: event.target.value 
    }); 
}, 
changeContent: function(event) { 
    this.setState({ 
     content: event.target.value 
    }); 
}, 
addBlog: function(ev) { 
    console.log("hit hit"); 
}, 
render: function() { 
    return (
       <form onSubmit={this.addBlog(this)}> 
        <div> 
         <label htmlFor='picure'>Picture</label> 
         <div><input type='file' id='picture' value={this.state.picture} /></div> 
        </div> 
        <div> 
         <input className="form-control" type='text' id='content' value={this.state.title} onChange={this.changeTitle} placeholder='Title' /> 
        </div> 
        <div> 
         <input className="form-control" type='text' id='content' value={this.state.content} onChange={this.changeContent} placeholder='Content' /> 
        </div> 
        <div> 
         <button className="btn btn-default">Add Blog</button> 
        </div> 
       </form> 

    ); 
    } 
}); 

La cosa divertente è quando uso onChange={this.changeTitle (this)}, l'evento, ma la variabile EV nella funzione changeTitle non è quello corretto.

+0

[funziona per me] (http://jsfiddle.net/dx8mq8dj/2/) . – Mathletics

+0

posso chiederti come lo hai configurato, sapevo che avrebbe dovuto funzionare. – Cekaleek

+0

Ho copiato il tuo codice esattamente come lo hai nel fiddle collegato, http://jsfiddle.net/dx8mq8dj/2/ – Mathletics

risposta

6

Prova:

onChange={(evt) => this.changeTitle(evt)} 

o:

onChange={this.changeTitle.bind(this)} 

invece di:

onChange={this.changeTitle} 
+0

onChange = {(evt) => props.onChangeDate (evt)} utilizzando questo paradigma: https://facebook.github.io/flux/docs/flux-utils.html –

+3

Se la funzione è vincolata correttamente ... perché tutti e 3 di questi non funzionano? –

+0

Si prega di spiegare perché quello superiore funziona e quello in basso non è – Mazzy

Problemi correlati