莫回?zé)o
2023-12-14 15:51:59
我是全棧開(kāi)發(fā)新手,我正在嘗試編寫(xiě)一些代碼來(lái)更好地理解 React JS 和 Material UI 的前端。我編寫(xiě)了一個(gè)對(duì)話框來(lái)將帖子發(fā)送到后端,并嘗試使用一些無(wú)線電來(lái)選擇每個(gè)值,但它們沒(méi)有正確評(píng)估。我是新手,所以請(qǐng)耐心等待,我向您展示我的代碼:class NewAdv extends Component { state = { open:false, type:'Sell', body:'', errors:{} }; radioChange = (event) => { this.setState({type: event.target.value}); console.log(this.state.type) };render() { return ( <RadioGroup aria-label="Type" name="type" color="primary" value={this.state.type} onChange={this.radioChange}> <FormControlLabel type="Sell" control={<Radio />} label="Sell" /> <FormControlLabel type="Trade" control={<Radio />} label="Trade" /> <FormControlLabel type="Other" control={<Radio />} label="Other" /> </RadioGroup> )}我能怎么做?
1 回答

慕尼黑5688855
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
您正在從目標(biāo)中獲取價(jià)值,但您的目標(biāo)并未定義該價(jià)值。
在 FormControlLabel 上,將類(lèi)型與值交換
做這個(gè)
<RadioGroup aria-label="Type" name="type" color="primary"
value={this.state.type} onChange={this.radioChange}>
<FormControlLabel value="Sell" control={<Radio />} label="Sell" />
<FormControlLabel value="Trade" control={<Radio />} label="Trade" />
<FormControlLabel value="Other" control={<Radio />} label="Other" />
</RadioGroup>
添加回答
舉報(bào)
0/150
提交
取消