2015-10-15 76 views
2

我通過POST請求發送一些數據到數據庫中,我有我的應用程序複選框,我需要用state在這種情況下如何處理複選框?

我使用this library這是混淆了我一點來處理。

在這裏,我有我的渲染方法

<Checkbox value="Active" ref="Active" defaultChecked={true} onCheck={this._isChecked} /> 

和功能複選框來處理它

_isChecked =() => { 
    console.log('Checked: '); 
    } 

我需要它是checked = true默認。

現在,在這裏我有我使用,以便將數據發送到post要求

_addDealer =() => { 
    CreateDealersActions.createDealer({ 
     DealerName : this.refs.DealerName.getValue(), 
     CardId  : this.refs.CardId.getValue(), 
     NickName : this.refs.NickName.getValue(), 
     Picture : 'http://lorempixel.com/150/150/', 
     Active  : // HERE I NEED TO SET THE VALUE OF THE CHECKBOX 
     LegalId : this.refs.LegalId.getValue(), 
     TypeId  : this.refs.TypeId.getValue(), 
    }); 
    } 

中只看該功能的Active : // HERE I NEED TO SET THE VALUE OF THE CHECKBOX部分功能,還有就是我需要把價值複選框。

那麼,我應該知道爲了發送正確的數據在密鑰Active,因爲我使用這個庫,我需要把state?或者還有其他方法嗎?

回答

1

我會回答這個問題,因爲可能你們中的一些人不知道我正在使用的圖書館,這是一個在屁股疼痛,文檔是可怕的。

您不需要設置初始狀態,因爲複選框組件已經帶有一個附件。所以,爲了讓你獲得複選框的價值,你不需要設置一個函數。有了這個,我沒有足夠的:

<Checkbox value="Active" ref="Active" defaultChecked={true} /> 

    _addDealer =() => { 
    CreateDealersActions.createDealer({ 
     DealerName : this.refs.DealerName.getValue(), 
     CardId  : this.refs.CardId.getValue(), 
     NickName : this.refs.NickName.getValue(), 
     Picture : 'http://lorempixel.com/150/150/', 

     Active  : this.refs.Active.state.switched, 

     LegalId : this.refs.LegalId.getValue(), 
     TypeId  : this.refs.TypeId.getValue(), 
    }); 
    } 

這樣:this.refs.Active.state.switched足以讓複選框的正確的值。