As shown in the picture, I want to automatically select all after single selection. How to achieve this?
Writing like this can be achieved, but every time I change this global variable, I always feel that it is a trap. Is there any good way to solve it?
淡淡烟草味2017-05-19 10:34:21
forEach
这个方法是没办法提前退出的。只能用 for
Loop
For logic like yours, you can update the view firstmap
一下返回符合勾选条件的数组,在forEach
if(this.productList.every(item => item.checked)) {
_this.checkAllF = true
}
滿天的星座2017-05-19 10:34:21
Use some or every for early exit, and what is the relationship between your function description and early exit
習慣沉默2017-05-19 10:34:21
@crp205’s answer is correct. some
will interrupt the loop if it returns true
, and every
returns false
Just terminate the loop.some
如果返回 true
就会中断循环, every
有一项返回 false
就终止循环.
数组的遍历只有这两个支持跳出循环了,否则就得用 for
Only these two support for array traversal to break out of the loop, otherwise you have to use for
阿神2017-05-19 10:34:21
Why doesn’t js have this syntax:
document.getElementsByxxx.checked(true/false)
means to get the number of checked or unchecked checkboxes/radios in the same category.