[英]Can I create several levels of nested objects?
Working on a project where I need to create an object containing several data sets that each have their own subsequent data sets. 在需要创建一个包含多个数据集的对象的项目上,每个数据集都有自己的后续数据集。 Not sure if this is excessive but I need to be able to accomplish something along these lines. 不知道这是否过多,但我需要能够按照这些原则完成工作。
Here's an example of what I mean, this doesn't work but it should give an idea: 这是我的意思的示例,这不起作用,但是应该给出一个主意:
var menu = {
"appetizers": {
soup: {
num1: "beef",
num2: "chicken",
num3: "vegetarian": {
v1: "soy",
v2: "tomato",
};
},
"salad": {
sal1: "apple",
sal2: "egg",
}
}
};
Yes, look at the object below. 是的,请看下面的物体。 You can do something like that. 你可以做类似的事情。
Only remember that objects are key value pairs and so for that it has to be in the form of: 仅记住对象是键值对,因此必须采用以下形式:
{key1:value1,
key2:{valueKey: valueValue}
}
Hence the following works: 因此,以下工作:
var menu = { "appetizers": { "soup": { "num1": "beef", "num2": "chicken", "num3": "vegetarian", "num4": { "v1": "soy", "v2": "tomato", } }, "salad": { "sal1": "apple", "sal2": "egg", } } }; console.log(menu);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.