0
我似乎無法一起計算一些數字。當我想用:在jQuery數組中計數
for (var key in week_total) {
$("." + key).html(week_total[key]);
}
我得到一個NaN
和的thereforce每個組有一個NaN
。這是甚至使用week_total[group] = week_total[group] + work_minutes;
的正確方法嗎?
我的腳本:
drawCallback: function (settings) {
var api = this.api(), data;
var rows = api.rows({page: 'current'}).nodes();
var last = null;
var week_total = new Array;
api.column(weekColumn, { page: 'current' }).data().each(function (group, i) {
var work_hours = api.column(hourColumn).data()[i].split(':');
var work_minutes = (+ work_hours[0]) * 60 + (+ work_hours[1]);
week_total[group] = week_total[group] + work_minutes;
if (last !== group) {
$(rows).eq(i).before('<tr><td colspan="5">{{ trans('admin.worktime.field.week') }} ' + group + '</td><td colspan="3" style="font-style:italic;" class="' + group + '"></td></tr>');
last = group;
}
});
for (var key in week_total) {
$("." + key).html(week_total[key]);
}
var array = {
work_month: work_month,
work_year: work_year
};
history.pushState(null, null, '?' + $.param(array));
drawDataTable(this);
}
哪裏旅遊week_total在week_total [組]初始化,哪些不確定? – Sabik
@Sabik你是什麼意思? 'week_total'被初始化爲'var week_total = new Array;',並且已經用在for(var key in week_total){'part。 –