2015-07-06 23 views
12

Ben girdi etiketinde aşağıdaki kodonFocus ve onBlur işleneceğini tepki vermez

<ElementsBasket name='nextActionDate' 
         data={this.props.newLead.get('actions').get('nextActionDate')}> 
       <div className="form-group"> 
       <span className="glyphicon glyphicon-calendar">Calendar </span> 
       <span className="glyphicon glyphicon-triangle-bottom" ></span> 

        <input type="text" className="form-control" onFocus={this.type='date'} onBlur={this.type='text'} 
         placeholder="Enter your date here." 
         value={this.props.newLead.get('actions').get('nextActionDate')} 
         onChange={onFieldChanged.bind(this, 'actions.nextActionDate')} 
         />  
       </div> 
       </ElementsBasket> 

, bir yer tutucu metin varsayılan olarak giriş alanında görünmesini sağlamak için çalışıyorum ve tıklandığında istediğim var tarih olarak değiştirilecek tip. Ve sorun tıklandığında krom üzerinde eleman incelendiğinde görünüyor. OnFocus ve onBlur'da gösterilmez.

Ps: Hatta onClick aynı sorunu

+0

bileşeninizin durumu değişene kadar görüntülenmez ... – coma

+0

ilk kez oluşturulur ancak bundan sonra durumu https://facebook.github.io/react değiştirerek oluşturmayı tetiklemeniz gerekir. /docs/component-specs.html – coma

cevap

17

Bu aradığınız ne mi var gibi görünüyor?

http://codepen.io/comakai/pen/WvzRKp?editors=001

var Foo = React.createClass({ 
    getInitialState: function() { 

    return { 
     type: 'text' 
    }; 
    }, 
    onFocus: function() { 

    this.setState({ 
     type: 'date' 
    }); 
    }, 
    onBlur: function() { 

    this.setState({ 
     type: 'text' 
    }); 
    }, 
    render: function() { 

    return(
     <input 
     type={ this.state.type } 
     onFocus={ this.onFocus } 
     onBlur={ this.onBlur } 
     placeholder="Enter your date here." 
     /> 
    ) 
    } 
}); 

React.render(<Foo/>, document.body); 

Yukarıda yorumladı ettiğimiz gibi, yöntem ilk kez tetikler ve bundan sonra her devlet değişikliği (ve shouldComponentRender durumda doğrudur dönerse, uygulandığı takdirde) işlemek:

https://facebook.github.io/react/docs/component-specs.html