1
是否有一种方便的方法来过滤bigObject
只有在filterInterface
中定义的属性才能获得filteredObject
作为输出?如何根据过滤器对象过滤对象
大对象有很多属性,我想剥离信息到我需要的属性(将它保存到某处,不想/不能保存完整的对象)。
I prepared the following code as a jsfiddle here.
// My big object
var bigObject = {
prop1: {
prop2: {
prop3: 123,
prop4: 456,
prop5: "TEST"
},
prop6: 789,
prop7: "xxx"
},
prop8: 5.6,
prop9: 3
};
// My "interface" to filter the object
var filterInterface = {
prop1: {
prop2: {
prop3: true,
},
prop7: true
}
};
// My expected result, only the properties of
// big Object which match the interface
var filteredObject = {
prop1: {
prop2: {
prop3: 123,
},
prop7: "xxx"
}
};
完美,完蛋了。谢谢! – Marc 2012-04-25 09:07:13