第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

全選已好用,但是單獨(dú)的checkbox不好用了,打不上√

全選已好用,但是單獨(dú)的checkbox不好用了,打不上√

回首憶惘然 2019-05-21 11:19:47
importReactfrom'react';import{Link}from'dva/router'import{Menu,Icon,Avatar,Layout,Breadcrumb,Button,notification,Select,Pagination,Checkbox,Input}from'antd';importlogofrom'../css/App.css';importayjsfrom'../css/ayjs.css';importReactDOMfrom'react-dom';classSiderextendsReact.Component{state={check:false,checks:false,}showInput=(e)=>{//全選和全不選console.log(e.target.checked);this.setState({check:e.target.checked,checks:e.target.checked,})}onChangea(e){console.log(`checked=${e.target.checed}`);}render(){return();}};exportdefaultSider
查看完整描述

2 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊

就你的代碼而言,單選沒效果是因?yàn)?,onChange的時(shí)候this.state.checks的狀態(tài)沒有改變,this也沒有傳入方法里面。改正后onChangea(e){
this.setState({
checks:e.target.checked,
});
}這時(shí)你會(huì)發(fā)現(xiàn)單選后所有的Checkbox都被選中了,是因?yàn)槟鉉heckbox設(shè)置的checked都是this.state.checks,所以狀態(tài)都會(huì)改變。所以你的代碼本身就不應(yīng)該這樣寫,這里可以用CheckboxGroup去實(shí)現(xiàn),具體代碼可參考
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-21
?
楊魅力

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊

render
return(
c)}onChange={()=>this.onChange()}/>
this.onChange(1)}/>
this.onChange(2)}/>
this.onChange(3)}/>
);
state
constructor(props){
super(props);
this.state={checks:[false,false,false]};
}
onChange
onChange(index){
let{checks}=this.state;
if(!index){
checks=checks.map(()=>!checks.some(c=>c));
}else{
checks=checks.map((c,i)=>{
if((i+1)===Number(index)){
return!c;
}
returnc;
});
}
this.setState({checks});
}
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-21
  • 2 回答
  • 0 關(guān)注
  • 491 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)