vue 判断两个列表是否重复

  async handleCrudSelect(e) {
      const that = this;
      let count = 0;
      // displayValueList 显示值
      // rawValueList 原值
      // 弹窗选择完数据后向后台发起 每条数据新增一条历史数据的请求
      // eslint-disable-next-line array-callback-return
      e.displayValueList.map((item) => {
        if (that.displayValueList.findIndex((preItem) =>
        // 根据preItem中的int_id属性来判断这个item是否存在,如果是,返回true,否返回false,继续下面一条数据的遍历,以此类推
        // eslint-disable-next-line implicit-arrow-linebreak,brace-style
        // eslint-disable-next-line no-unused-expressions,implicit-arrow-linebreak
          preItem.int_id === item.int_id,
        // eslint-disable-next-line function-paren-newline
        ) === -1) {
          // eslint-disable-next-line no-plusplus
          count++;
          that.displayValueList.push(item);
        }
      });

      e.rawValueList.map((item) => that.rawValueList.findIndex((preItem) =>
      // 根据preItem中的int_id属性来判断这个item是否存在,如果是,返回true,否返回false,继续下面一条数据的遍历,以此类推
      // eslint-disable-next-line implicit-arrow-linebreak
        preItem.int_id === item.int_id,
        // eslint-disable-next-line function-paren-newline
      ) === -1 && that.rawValueList.push(item));
      if (count !== 0) {
        // 需要新增HIS数据
        await request.postUrl('/insertHis', {
          data: { rawValueList: this.rawValueList },
          flowId: this.flowId,
        }).then((res) => {
          if (res.resultFlag.code !== 0) {
            this.$message.error(res.resultFlag.errorMessage);
          } else {
            this.$message.success('添加数据成功');
          }
        });
      }
    }

 

posted @ 2022-07-21 10:48  陈扬天  阅读(701)  评论(0编辑  收藏  举报