我正在尝试对从 json 响应中获得的值求和:
JS代码
var daySum = {};
$.each(json, function (i, v) {
date = Number(v.eDate.split('.')[0]);
eValue = Number(v.eValue);
daySum[date] += eValue;
console.log(date); //14 , 18 , 19, 19
console.log(eValue); //30.00 , 20.00 , 20.50, 14.30
});
console.log(daySum); //Object { 14=NaN, 18=NaN, 19=NaN}
JSON结构:
[
{
"eDate": "14.06.2013",
"eValue": "30.00"
},
{
"eDate": "18.06.2013",
"eValue": "20.00"
},
{
"eDate": "19.06.2013",
"eValue": "20.50"
},
{
"eDate": "19.06.2013",
"eValue": "14.30"
}
]
我在这里做错了什么?