现有对象内的多个对象

时间:2015-06-03 03:27:45

标签: javascript

目前我可以通过companyServiceRateOffsets[n]访问此类型的数组:

var companyServiceRateOffsets = {
    3: { timeworked: 12.25, billabletime: 15.00 },
    15: { timeworked: 14.25, billabletime: 25.00 },
    24: { timeworked: 17.25, billabletime: 35.00 },
}

我可以通过在现有数据中包含多个对象来扩展此数组吗?像:

var companyServiceRateOffsets = {
    3: {
         { timeworked: 12.25, billabletime: 15.00 },
         { timeworked: 13.25, billabletime: 16.00 },
    },
    15: {
         { timeworked: 14.25, billabletime: 25.00 },
         { timeworked: 15.25, billabletime: 26.00 },
    },
    24: {
         { timeworked: 17.25, billabletime: 35.00 },
         { timeworked: 18.25, billabletime: 36.00 },
    },
}

以上示例不起作用,但理想情况下应该如此。请帮忙。

1 个答案:

答案 0 :(得分:0)

你想要一个数组

var companyServiceRateOffsets = {
    3: [
         { timeworked: 12.25, billabletime: 15.00 },
         { timeworked: 13.25, billabletime: 16.00 }
    ],
    15: [
         { timeworked: 14.25, billabletime: 25.00 },
         { timeworked: 15.25, billabletime: 26.00 }
    ],
    24: [
         { timeworked: 17.25, billabletime: 35.00 },
         { timeworked: 18.25, billabletime: 36.00 }
    ]
};