I have a data structure like this :
(我有一个像这样的数据结构:)
var someObject = {
'part1' : {
'name': 'Part 1',
'size': '20',
'qty' : '50'
},
'part2' : {
'name': 'Part 2',
'size': '15',
'qty' : '60'
},
'part3' : [
{
'name': 'Part 3A',
'size': '10',
'qty' : '20'
}, {
'name': 'Part 3B',
'size': '5',
'qty' : '20'
}, {
'name': 'Part 3C',
'size': '7.5',
'qty' : '20'
}
]
};
And I would like to access the data using these variable :
(我想使用这些变量访问数据:)
var part1name = "part1.name";
var part2quantity = "part2.qty";
var part3name1 = "part3[0].name";
part1name should be filled with someObject.part1.name
's value, which is "Part 1".
(part1name应该用someObject.part1.name
的值填充,即“ Part 1”。)
Same thing with part2quantity which filled with 60.(part2quantity填充60。)
Is there anyway to achieve this with either pure javascript or JQuery?
(无论如何,可以使用纯JavaScript或JQuery来实现这一点?)
ask by Komaruloh translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…