我正在使用 AngularJS 进行 $resource 调用以获取一些 JSON 格式的值。我的要求是我有一个模型元素需要一个 Javascript 数组的形式:
[
[1328983200000, 40],
[1328983200000, 33],
[1328983200000, 25],
[1328983200000, 54],
[1328983200000, 26],
[1328983200000, 25]
];
显示在 Flot 图表中。此信息包含在 JSON 中,如下所示:
{
"marks1":15,
"marks2":20,
"dailyMarks":{
"2013-02-27T07:25:35.000+0000":40,
"2013-03-01T07:25:35.000+0000":33,
"2013-02-26T07:25:35.000+0000":25,
"2013-02-23T07:25:35.000+0000":54,
"2013-03-03T10:12:59.000+0000":26,
"2013-03-02T07:12:59.000+0000":25},
}
其中“dailyMarks”包含我需要的元素。我可以将“dailyMarks”转换为 Javascript 数组,但它似乎不起作用:(下面是我的控制器代码)
function MyController($scope, $resource) {
var User = $resource('/marks/fetch?from=:from&to=:to', {from: inStartDate, to: inEndDate}, {
getAll: {method: 'GET', isArray: false}
});
$scope.changeDate = function(fromDate, toDate) {
$scope.marks = User.getAll({from: fromDate, to: toDate});
};
var imarks = User.getAll();
$scope.marks = imarks;
var list = imarks.dailyMarks, arr = [];
for (var key in list) {
arr.push([+new Date(key), list[key]]);
}
$scope.myModel = arr;
};
我究竟做错了什么?我在模型中得到空白 arr[] 。:( :( 请指导我。