var data={
"soft":"1111",
"soft.type":"1111",
"soft.condition":"1111",
"wonder":"1111",
"wonder.WONDER":"1111",
"wonder.WONDER.BS_TEST":"1111",
"wonder.WONDER.DB2数据类型":"1111",
"wonder.WONDER.DEP_TABLE":"1111",
"wonder.WONDER.DIC_TABLE":"1111",
"wonder.WONDER.TABLE8_NF":"1111",
"wonder.WONDER.基本信息":"1111",
"wonder.WONDER.姓名":"1111",
"wonder.WONDER.数据类型":"1111"
}
var result=[{
"name":"soft",
"val":"1111",
"children":[{
"name":"type",
"val":"1111",
},{
"name":"condition",
"val":"1111",
}]
},{
"name":"wonder",
"val":"1111",
"children":[{
"name":"WONDER",
"val":"1111",
"children":[{
"name":"BS_TEST",
"val":"1111"
},{
"name":"DB2数据类型",
"val":"1111"
},{
"name":"DEP_TABLE",
"val":"1111"
},{
"name":"姓名",
"val":"1111"
},{
"name":"数据类型",
"val":"1111"
}]
}]
}]
I’m looking for a way to convert data into result. I’ve been stuck on it all afternoon and I really can’t write it out. Thank you! !
I’m in a hurry and haven’t written any comments yet. You can run it and see~
For convenience, I didn’t use ES6 to write it, so I’ll make do with it~
If you can ensure that the order of data is a, a.b, a.b.c, you can also reduce more than a dozen lines of code: