抱着猫睡觉的鱼_ 2021-09-07 19:51 采纳率: 51.7%
浏览 309
已结题

vue sku笛卡尔积数据插入表格

需求如下:网上搜了一下这种数据叫做笛卡尔积,但是现在需要的数据还造不出来

img

img

img


这个是数据我需要取specItem和specName

img


点击黄色,s和m 最后插入到表格中应该是第一行黄色s, 第二行黄色m

所有的代码如下,求详细解释

 handleCurrentHelpTable(val){
      this.selectProductId = val.id; //规格模板选择数据行的id
      this.selectHelpData = val;
      // sku规格名字
      this.productSpecs = val.specItems;
      console.log(val)
      let tableCategoryList = [];
      let productSpecDetail = [];
      if(val.specItems.length !=0){
        //外层数组
        let desArray = val.specItems;
        for(let i=0;i<desArray.length;i++){
          let tempObj = {};
          let tempHeaderFileds = {}; //动态表头字段
          tempObj.specName = desArray[i].specName;//规格名字'颜色','测试'
          let children = desArray[i].specItem.split(','); //规格值'[1111],[2222]'
          let childrenList = [];  
       
          
          for(let j=0;j<children.length;j++){  
            let tempChidrenObj = {
              specItem:children[j],
              image:"",
            }
            childrenList.push(tempChidrenObj);
          }
          tempObj.specItems = childrenList;
          tempObj.productspecId =  this.selectProductId;
          childrenList.image =this.imgLoopList.image;
          console.log(  this.uploadImgName,'dsadsadsasa')
          tempObj.value = `attributeName${i+1}`;  
          tempObj.isCheck = false;
          //动态表头的数据name: "颜色"value: "attributeName2"
          tempHeaderFileds.value = `attributeName${i+1}`;
          tempHeaderFileds.name = desArray[i].specName;  //productSkus数组传入的字段名
          tableCategoryList.push(tempObj);
          //动态表头
          productSpecDetail.push(tempHeaderFileds); 
        }
      }
      this.tableCategoryList = tableCategoryList; //规格数据
      this.productSpecDetail = productSpecDetail; //动态表头
      var arr = [
        ['黑色', '白色', '蓝色'],
        ['8GB', '16GB', '32GB'],
        ['大', '中', '小']
    ];
     
    console.log(this.descartes(arr),'this.tableCategoryList');
          
      console.log(this.tableCategoryList,'===========================')
      console.log('帮助框table的数据--------------', this.selectHelpData)
    },
 //点击tag标签
    clickTag(value,field,indexId){
      console.log(value,indexId,this.chooseTag,'-----------------')
      let that = this;
      for(let c=0;c<this.chooseTag.length;c++){
        if(this.chooseTag[c].indexId==indexId){
          let tableIndex = this.chooseTag[c].tableIndex;
          this.skuTable.splice(this.chooseTag[c].tableIndex,1);
          this.chooseTag.splice(c,1);
          for(let e=0;e<that.chooseTag.length;e++){
            if(that.chooseTag[e].tableIndex>tableIndex){
              that.chooseTag[e].tableIndex -= 1;
            }
          }
          console.log(this.chooseTag,999999999999999999999)
          return;
        }
      }
      // this.activeProduc = item;
      // console.log("我点击了标签"+item);
      // console.log(this.checkboxGroup)
    
      this.addProductSkuBtn();
      this.skuTable[this.skuTable.length-1][field] = value.specItem; //数组长度为1时下标为0,需要length-1赋值
      // console.log(this.skuTable,'skutable======')
      // console.log(this.skuTable.length,this.skuTable.length-1,'lenghh=====')
      let chooseObj = {
        indexId:indexId,
        tableIndex:this.skuTable.length-1,
      }
      //indexId: "23" tableIndex: 0   23代表选中了第二行第三个
      this.chooseTag.push(chooseObj);  
      console.log(this.skuTable,'this.chooseTag');
      let attributeName1 = [];
      let attributeName2 = [];
      let finalArray = [];
      this.skuTable.forEach(item=>{
        console.log(item,'item---------------------')
        attributeName1.push(item.attributeName1);
        attributeName2.push(item.attributeName2);
      })
      finalArray.push(attributeName1)
      finalArray.push(attributeName2)
      // let finalArr = attributeName1.concat(attributeName2);
      console.log(this.descartes(finalArray) ,'finalArr11111111111111111111')
    },
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 9月15日
    • 创建了问题 9月7日

    悬赏问题

    • ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。
    • ¥15 请问用arcgis处理一些数据和图形,通常里面有一个根据点划泰森多边形的命令,直接划的弊端是只能执行一个完整的边界,但是我们有时候会用到需要在有很多边界内利用点来执行划泰森多边形的命令
    • ¥30 在wave2foam中执行setWaveField时遇到了如下的浮点异常问题,请问该如何解决呢?
    • ¥20 看图片)删除这个自动化录屏脚本就一直报错找不到脚本文件,如何解决?(相关搜索:bat文件)
    • ¥750 关于一道数论方面的问题,求解答!(关键词-数学方法)
    • ¥200 csgo2的viewmatrix值是否还有别的获取方式
    • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
    • ¥15 请把下列每一行代码完整地读懂并注释出来
    • ¥15 pycharm运行main文件,显示没有conda环境
    • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件