在这个例子中,我想提取1)员工编号和2)他/她的所有任务。2)可以工作,但1)给我一个对象而不是数字...
我是否必须将员工编号设置为键/值对才能提取值?
我是否必须将员工编号设置为键/值对才能提取值?
var s = {
"schedule": {
"employees": {
"1000": {
"tasks": [
{
"task": "task1",
"site": "site1",
"from": "0900",
"to": "1000"
},
{
"task": "task2",
"site": "site2",
"from": "0900",
"to": "1000"
}
]
},
"2000": {
"tasks": [
{
"task": "task3",
"site": "site3",
"from": "0900",
"to": "1000"
},
{
"task": "task4",
"site": "site4",
"from": "0900",
"to": "1000"
}
]
}
}
}
}
for (var i in s["schedule"]["employees"]) {
// this gives me the object, I would like the employee number (eg:1000)
console.log(s["schedule"]["employees"][i]);
// this gives me the task number
for (var j in s["schedule"]["employees"][i].tasks) {
console.log(s["schedule"]["employees"][i].tasks[j].task);
}
}
我不知道为什么我很难理解这个。我是唯一一个遇到这种情况的人吗?