Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按电路板名称对对象进行分组_Javascript_Arrays_Json_Arraylist_Lodash - Fatal编程技术网

Javascript 按电路板名称对对象进行分组

Javascript 按电路板名称对对象进行分组,javascript,arrays,json,arraylist,lodash,Javascript,Arrays,Json,Arraylist,Lodash,我有一个很长的JSON,它是一个对象数组。每个元素都有属性名和板。我需要根据董事会的名字加入他们 [ { "name": "school education", "boards": [ { "name": "CBSE", "grades": [ { "name&

我有一个很长的JSON,它是一个对象数组。每个元素都有属性名和板。我需要根据董事会的名字加入他们

[
  {
    "name": "school education",
    "boards": [
      {
        "name": "CBSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "french"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "CBSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "physical education"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "CBSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "chinese"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "CBSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "sanskrit"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "CBSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "spanish"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "CBSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "russian"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "JKBOSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "french"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "JKBOSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "physical education"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "JKBOSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "chinese"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "JKBOSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "sanskrit"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "JKBOSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "spanish"
            ]
          }
        ]
      }
    ]
  },
  {
    "name": "school education",
    "boards": [
      {
        "name": "JKBOSE",
        "grades": [
          {
            "name": "class 1",
            "subject": [
              "russian"
            ]
          }
        ]
      }
    ]
  }
]
我有上面的JSON,我需要把它转换成这种格式。所以我的JSON现在将有一个名为的键,它由

学校教育 以及其他键盘,这些键盘将根据名称对所有项目进行分组


有效的做法是在每个级别进行分组和映射

您需要按项目名称分组;然后在每个项目内,按板分组;在每个板上,按等级分组。对于每个嵌套项,这会变得更复杂

const main=()=>{
const result=\ uu0.chain(data())
.groupBy('名称')
.map((值1,键1)=>({
姓名:key1,
电路板:u.链(值1)
.groupBy('boards[0].name')
.map((值2,键2)=>({
姓名:key2,,
等级:链(值2)
.groupBy('boards[0].grades[0].name')
.map((值3,键3)=>({
名称:value3[0]。电路板[0]。等级[0]。名称,
主题:u.flattedeep(value3.map)(项目=>{
返回项目.boards.map(board=>{
返回板.grades.map(grade=>{
返回年级。科目;
})
})
}))
}))
}))
}))
.value();
控制台日志(结果);
};
常量数据=()=>[{
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“法语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“科目”:[“体育”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“中文”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主语”:[“梵语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“西班牙语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“俄语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“法语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“科目”:[“体育”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“中文”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主语”:[“梵语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“西班牙语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“俄语”]
}]
}]
}];
main()
.as控制台包装{top:0;最大高度:100%!重要;}

有效的做法是在每个级别进行分组和映射

您需要按项目名称分组;然后在每个项目内,按板分组;在每个板上,按等级分组。对于每个嵌套项,这会变得更复杂

const main=()=>{
const result=\ uu0.chain(data())
.groupBy('名称')
.map((值1,键1)=>({
姓名:key1,
电路板:u.链(值1)
.groupBy('boards[0].name')
.map((值2,键2)=>({
姓名:key2,,
等级:链(值2)
.groupBy('boards[0].grades[0].name')
.map((值3,键3)=>({
名称:value3[0]。电路板[0]。等级[0]。名称,
主题:u.flattedeep(value3.map)(项目=>{
返回项目.boards.map(board=>{
返回板.grades.map(grade=>{
返回年级。科目;
})
})
}))
}))
}))
}))
.value();
控制台日志(结果);
};
常量数据=()=>[{
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“法语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“科目”:[“体育”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“中文”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主语”:[“梵语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“西班牙语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“名称”:“CBSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“俄语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“法语”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“科目”:[“体育”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“中文”]
}]
}]
}, {
“名称”:“学校教育”,
“董事会”:[{
“姓名”:“JKBOSE”,
“职系”:[{
“名称”:“1类”,
“主题”:[“sa
name: "school education",
    boards: [
      {
        name: "CBSE",
        grades: [
          {
            name: "Class 1",
            subjects: ["Maths", "Hindi", "EVS", "English"]
          },
          {
            name: "Class 2",
            subjects: ["Maths", "Hindi", "EVS", "English"]
          },
          {
            name: "Class 3",
            subjects: ["Maths", "Hindi", "EVS", "English"]
          },
          {
            name: "Class 4",
            subjects: ["Maths", "Hindi", "EVS", "English"]
          },
          {
            name: "Class 5",
            subjects: ["Maths", "Hindi", "EVS", "English"]
          },
          {
            name: "Class 6",
            subjects: [
              "Maths",
              "Hindi",
              "English",
              "History",
              "Geography",
              "Civics",
              "Sanskrit",
              "Science"
            ]
          },