arr.some()与arr.every();应用场景

arr.some()与arr.every();

// tabledata第一层只要有在selection里面就是全选
      const isSelect = selection.some((el) => {
        const tableDataIds = this.tableData.map((j) => j.spuCode);
        return tableDataIds.includes(el.spuCode);
      });
      // tableDate第一层只要有不在selection里面就是全不选
      const isCancel = !this.tableData.every((el) => {
        const selectIds = selection.map((j) => j.spuCode);
        return selectIds.includes(el.spuCode);
      });
      if (isSelect) {
        selection.map((el) => {
          if (el.children) {
            // 解决子组件没有被勾选到
            this.setChildren(el.children, true);
          }
        });
      }
      if (isCancel) {
        this.tableData.map((el) => {
          if (el.children) {
            // 解决子组件没有被勾选到
            this.setChildren(el.children, false);
          }
        });
      }

其他循环更多用法见:


版权声明:本文为u011565547原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。