React Tips
1.Class切换
(1)在constructor里定义初始状态 相当于开关 给个初始赋值 然后在回调函数中进行切换
constructor(props) {
super(props);
this.confirm = this.confirm.bind(this);
this.state={
bOK:false
}
};
(2)this.confirm为回调函数
<Popconfirm placement="right" title={text1} onConfirm={this.confirm} okText="是" cancelText="否">
<Button type="primary" className={this.state.bOK1 ? "btn battery" : "btn"}>11111</Button>
</Popconfirm>
(3)在这里进行状态切换 可以用class id ref等获取到元素 官方推荐ref 但存在this指向问题 用class不能直接进行Btn.className=''。[坑]直接用class的话不能对自己进行赋值
建议使用开关来控制class的切换 另外 set/get/remove+Attribute都可以使用
confirm() {
let Btn=document.getElementsByClassName('btn');
this.setState({ bOK: true });
};
2.Map
(1)用法1
battery.map((item,i) => {
if(item>11&&item<13){
}else{
openNotificationWithIcon('warning',(i+1),'电压不正常')()
}
});
(2)用法2{battery.map((item,i) => {return <li></li>})}
(3)
import lds from 'lodash';
const voltage = lds.reduce(batterystate, (result,item)=>{ return result+item },0);遍历求和
const temperature: lds.max(batterystate.data['cell-temp'])遍历求最大值

浙公网安备 33010602011771号