如何在table中显示特定月份的数据?
How to display data for a specific month in a table?
我想知道如何在 table 中显示特定月份的数据。
有一个 table 列 [EmployeeId,Date,StartTime,EndTime]。
我想按 Date 的月份过滤,但我不知道如何。
var AttendanceResult = [];
// Select employee number and current month data
var query = app.models.AttendanceMaster.newQuery();
query.filters.EmployeeId._equals = userNumber; // Match employee number
query.filters.Date._contains = roadMonth; // Including month
var records = query.run();
for (var i = 0; i < records.length; i++) {
AttendanceResult.push(records[i]);
}
return AttendanceResult;
由于上面代码中的"query.filters.Date._contains = roadMonth;"过滤器不起作用,
我认为这里有一个错误,
请告诉我。
有哪些过滤器示例?
您当然可以使用 appmaker 的脚本来实现这一点。根据您的示例构建,我看到您正在使用服务器脚本。以下代码段应该可以帮助您了解如何实现它,并且还可以产生您想要的结果:
function filterByMonth(month){
//get the selected month digit
month = month.toLowerCase();
var allMonths = {
"january": 0,
"february": 1,
"march": 2,
"april": 3,
"may": 4,
"june": 5,
"july": 6,
"august": 7,
"september": 8,
"october": 9,
"november": 10,
"december": 11
};
var monthDigit = allMonths[month];
// Select employee number and current month data
var selectedMonthStart = new Date();
selectedMonthStart.setMonth(monthDigit);
selectedMonthStart.setDate(1);
selectedMonthStart.setHours(0,0,-1,0);
var selectedMonthEnd = new Date();
selectedMonthEnd.setMonth(monthDigit+ 1);
selectedMonthEnd.setDate(1);
selectedMonthEnd.setHours(0,0,0,0);
var query = app.models.AttendanceMaster.newQuery();
query.filters.EmployeeId._equals = userNumber; // Match employee number
query.filters.Date._greaterThan = selectedMonthStart; // Including month start time
query.filters.Date._lessThan = selectedMonthEnd; // Including month end time
var AttendanceResult = query.run();
return AttendanceResult;
}
我想知道如何在 table 中显示特定月份的数据。
有一个 table 列 [EmployeeId,Date,StartTime,EndTime]。 我想按 Date 的月份过滤,但我不知道如何。
var AttendanceResult = [];
// Select employee number and current month data
var query = app.models.AttendanceMaster.newQuery();
query.filters.EmployeeId._equals = userNumber; // Match employee number
query.filters.Date._contains = roadMonth; // Including month
var records = query.run();
for (var i = 0; i < records.length; i++) {
AttendanceResult.push(records[i]);
}
return AttendanceResult;
由于上面代码中的"query.filters.Date._contains = roadMonth;"过滤器不起作用, 我认为这里有一个错误, 请告诉我。
有哪些过滤器示例?
您当然可以使用 appmaker 的脚本来实现这一点。根据您的示例构建,我看到您正在使用服务器脚本。以下代码段应该可以帮助您了解如何实现它,并且还可以产生您想要的结果:
function filterByMonth(month){
//get the selected month digit
month = month.toLowerCase();
var allMonths = {
"january": 0,
"february": 1,
"march": 2,
"april": 3,
"may": 4,
"june": 5,
"july": 6,
"august": 7,
"september": 8,
"october": 9,
"november": 10,
"december": 11
};
var monthDigit = allMonths[month];
// Select employee number and current month data
var selectedMonthStart = new Date();
selectedMonthStart.setMonth(monthDigit);
selectedMonthStart.setDate(1);
selectedMonthStart.setHours(0,0,-1,0);
var selectedMonthEnd = new Date();
selectedMonthEnd.setMonth(monthDigit+ 1);
selectedMonthEnd.setDate(1);
selectedMonthEnd.setHours(0,0,0,0);
var query = app.models.AttendanceMaster.newQuery();
query.filters.EmployeeId._equals = userNumber; // Match employee number
query.filters.Date._greaterThan = selectedMonthStart; // Including month start time
query.filters.Date._lessThan = selectedMonthEnd; // Including month end time
var AttendanceResult = query.run();
return AttendanceResult;
}