【发布时间】:2020-12-20 02:09:03
【问题描述】:
我有一个父对象和多个子对象,结构如下:
parent: {
child1: {
"aaa": {values: [], type: "string", title: "AAA"},
"bbb": {values: [], type: "string", title: "BBB"},
"ccc": {values: [], type: "string", title: "CCC"},
"ddd": {values: [], type: "string", title: "DDD"}
},
child2: {
"eee": {values: [], type: "string", title: "EEE"},
"fff": {values: [], type: "string", title: "FFF"},
"ggg": {values: [], type: "string", title: "GGG"},
"hhh": {values: [], type: "string", title: "HHH"}
},
child3: {
"iii": {values: [], type: "string", title: "III"},
"jjj": {values: [], type: "string", title: "JJJ"},
"kkk": {values: [], type: "string", title: "KKK"},
"lll": {values: [], type: "string", title: "LLL"}
}
}
现在我有一个函数,它返回一个子值作为子对象的键。例如:
function childVal() {
//do somehting
return "aaa";
}
现在根据这个值,我想获取整个子对象,例如:如果返回值是"bbb",我希望返回具有"bbb" 键的对象,在这种情况下是child1。
以下值的输出:
"aaa": return child1;
"ggg": return child2;
"bbb": return child1;
"lll": return child3;
这可能吗?
【问题讨论】:
-
你没有关闭
"lll": {values: [], type: "string", title: "LLL"}末尾的双引号。
标签: javascript object filtering