在以下 Javascript (JSON) 数组中,以下代码将遍历员工,但我如何使用 Javascript 或 jQuery/javascript 解决 1) 个人员工编号、2) 任务或 3) 站点?
$.each(mySchedule, function(i, obj) {
console.log(obj.employees);
});
var mySchedule =
{
"schedule": {
"employees": [{
"employee": "1000",
"tasks": [{
"task1": {
"site":"McDo",
"from":"0900",
"to":"1000"
}
},
{
"task2": {
"site":"McDo",
"from":"0900",
"to":"1000"
}
}]
},
{
"employee": "2000",
"tasks": [{
"task3": {
"site":"HJ",
"from":"0900",
"to":"1000"
}
},
{
"task4": {
"site":"KFC",
"from":"0900",
"to":"1000"
}
}]
}]
}
}
(编辑)我乐观地希望这样的事情会奏效。
$.each(mySchedule, function(i, obj) {
console.log(obj.site);
});