抱着猫睡觉的鱼_ 2022-03-14 09:07 采纳率: 51.7%
浏览 128

vue 数据处理的问题

数据如下,每一项的image根据attributeValue来赋值,所有的arrtibuteValue1相同值的image是一样的,比如第一项attributeValue1的值是"P.Ⅰ", 并且这一条的image是有值的话那么所有attributeValue1 等于p.I 的image都被赋值,attributeValue1的值会有多个,相同值的image是一样的,如果attributeValue1的image都没有值得话,以此类推attribute2,3,4... 优先级按照数字的顺序,应该如何修改,感谢各位

let arr = [
    {
        "image": "https://lumall.inspures.com/images/product/6985e333-dd45-45dc-b496-889400f1eb9a.png",
        "uniqueCategoryKey": "11,21,31",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅰ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "免税"
    },
    {
      
        "image": "https://lumall.inspures.com/images/product/7a2a169a-c08c-4492-914a-e6f878c3b204.png",
        "uniqueCategoryKey": "11,21,32",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅰ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "缓凝"
    },
    {
     
        "image": "",
        "uniqueCategoryKey": "12,21,31",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅱ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "免税"
    },
    {
    
        "image": "",
        "uniqueCategoryKey": "12,21,32",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅱ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "缓凝"
    }
]

想要的数据格式,相同attributeValue1这一项的image是相同的,优先去找attributeValue1的image如果没有继续往下找,以此类推

[
    {
      
        "image": "https://lumall.inspures.com/images/product/6985e333-dd45-45dc-b496-889400f1eb9a.png",
        "uniqueCategoryKey": "11,21,31",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅰ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "免税"
    },
    {
       
        "image": "https://lumall.inspures.com/images/product/6985e333-dd45-45dc-b496-889400f1eb9a.png",
        "uniqueCategoryKey": "11,21,32",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅰ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "缓凝"
    },
    {
       
        "image": "https://lumall.inspures.com/images/product/7a2a169a-c08c-4492-914a-e6f878c3b204.png",
        "uniqueCategoryKey": "12,21,31",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅱ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "免税"
    },
    {
       
        "image": "https://lumall.inspures.com/images/product/7a2a169a-c08c-4492-914a-e6f878c3b204.png",
        "uniqueCategoryKey": "12,21,32",
        "attributeName1": "种类1",
        "attributeValue1": "P.Ⅱ",
        "attributeName2": "强度2",
        "attributeValue2": "32.5",
        "attributeName3": "其他",
        "attributeValue3": "缓凝"
    }
]

  • 写回答

1条回答 默认 最新

  • 归来巨星 前端领域新星创作者 2022-03-14 09:35
    关注
    
        <script>
          let arr = [
            {
              skuCode: "cxzcxz",
              skuName: "fdgfdgfd",
              price: "",
              isShelf: "1",
              image: "https://lumall.inspures.com/images/product/6985e333-dd45-45dc-b496-889400f1eb9a.png",
              uniqueCategoryKey: "11,21,31",
              attributeName1: "种类1",
              attributeValue1: "P.Ⅰ",
              attributeName2: "强度2",
              attributeValue2: "32.5",
              attributeName3: "其他",
              attributeValue3: "免税",
            },
            {
              skuCode: "cxzcxz",
              skuName: "dvfdg",
              price: "",
              isShelf: "1",
              image: "",
              uniqueCategoryKey: "11,21,32",
              attributeName1: "种类1",
              attributeValue1: "P.Ⅰ",
              attributeName2: "强度2",
              attributeValue2: "32.5",
              attributeName3: "其他",
              attributeValue3: "缓凝",
            },
            {
              skuCode: "dsadsad",
              skuName: "vfvf",
              price: "",
              isShelf: "1",
              image: "123",
              uniqueCategoryKey: "12,21,31",
              attributeName1: "种类1",
              attributeValue1: "P.Ⅱ",
              attributeName2: "强度2",
              attributeValue2: "32.5",
              attributeName3: "其他",
              attributeValue3: "免税",
            },
            {
              skuCode: "vcxvcx",
              skuName: "dsadsadsa",
              price: "",
              isShelf: "1",
              image: "",
              uniqueCategoryKey: "12,21,32",
              attributeName1: "种类1",
              attributeValue1: "P.Ⅱ",
              attributeName2: "强度2",
              attributeValue2: "32.5",
              attributeName3: "其他",
              attributeValue3: "缓凝",
            },
          ];
          arr.forEach((item) => {
            let strImage = "";
            let strVal1 = "";
            if (item.image) {
              strImage = item.image;
              strVal1 = item.attributeValue1;
            }
            arr.forEach((element) => {
              if (element.attributeValue1 == strVal1) {
                element.image = strImage;
              }
            });
          });
          console.log(arr);
        </script>
    
    评论

报告相同问题?

问题事件

  • 修改了问题 3月14日
  • 创建了问题 3月14日

悬赏问题

  • ¥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 寻找公式识别开发,自动识别整页文档、图像公式的软件