在antd的checkbox的中看到如下代码,不明白e是什么?
onCheckAllChange = (e) => {
this.setState({
checkedList: e.target.checked ? plainOptions : [],
indeterminate: false,
checkAll: e.target.checked,
});
经过查阅资料后,加上自己的一点点理解大概能够明白其中的含义,不足之处欢迎专业人士指正。
1.e指代event事件,传递的是事件发生时的时间地点等参数
2.=>是箭头函数,(参数)=>{函数},参数传递到函数中,和普通的函数作用一样。具体可参考以下文件
3 ?和:什么意思
e.target.checked ? plainOptions : []
这是摘抄自Stack Overflow上的回答
It is called the Conditional Operator (which is a ternary operator).
It has the form of: condition ? value-if-true : value-if-false
the code is equivalent to
if (e.target.checked)
plainOptions;
else
[];
大意就是:它被称为条件运算符(也叫三元运算符),格式为: 条件?值(为真):值(为假),说了那么多,其实就是我们的if ,else语句
4.双感叹号的用法!!(double exclamation marks)
It converts a value to a boolean and ensures a boolean type
把一个值转换成布尔值
"foo" = "foo"
!"foo" = false
!!"foo" = true