lodash#unionWith JavaScript Examples

The following examples show how to use lodash#unionWith. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Company.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
/**
   * 选中父级后同时选中子集
   * @param {*Object} record 当前操作的行
   * @param {*boolean} selected 选中标记
   * @param {*Array} selectedRows 已经选中行数据
   */
  @Bind()
  selectChilds(record = {}, selected, selectedRows) {
    const { loading } = this.props;
    const { updateLoading, originList } = this.state;
    if (updateLoading || loading) return;
    this.setState({
      updateLoading: true,
    });
    let grandsonList = [];
    const childType = this.findChildType(record.typeCode);
    const childLists = originList.filter(
      (list) => list.parentId === record.dataId && list.typeCode && list.typeCode === childType
    );
    childLists.map((childList) => {
      const grandsonType = this.findChildType(childList.typeCode);
      grandsonList = unionWith(
        grandsonList,
        originList.filter(
          (list) =>
            list.parentId === childList.dataId && list.typeCode && list.typeCode === grandsonType
        )
      );
      return grandsonList;
    });
    let rows;
    if (selected) {
      rows = unionWith(unionWith(selectedRows, childLists), grandsonList);
    } else {
      rows = pullAllBy(pullAllBy(selectedRows, childLists, 'dataId'), grandsonList, 'dataId');
    }
    this.setState(
      {
        checkedList: uniqBy(rows, 'id'),
      },
      () => {
        this.handleSaveCompany();
      }
    );
  }