我想知道如何在表格中显示特定月份的数据。
有一个带有[EmployeeId,Date,StartTime,EndTime]列的表。 我想按日期月份过滤,但我不知道如何。
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;”上面代码中的过滤器不起作用, 我认为这里有一个错误, 请告诉我。
过滤器有哪些示例?
答案 0 :(得分:0)
您当然可以使用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;
}