
[英]filter array of objects on click by 'last month' and 'last week' using moment.js
[英]angular filter on click by 'last week' data
嗨,我是angel的新手,正在制作我的第一个模块。 本文非常有帮助。 我想按上周记录过滤数据。 我已经在mysql查询中找到了当前日期和给定日期的天数,在按钮上单击,我只是在设置DisTopic = 1之类的值,所以工作正常。
能否请您告诉我如何为day>=1 && day<=7
等范围应用过滤器
我正在使用以下:-
filter:{'topic': DisTopic,'attachment':attch, 'days':day}
请帮我。
正如其他用户所说,您确实可以使用自定义过滤器执行此操作。 但是,如果您发现自己编写了很多自定义滤镜,我建议您看一下角度滤镜模块。 使用此模块,您可以使用pick
过滤器执行所需的操作:
<div ng-repeat="task in tasks | pick: 'days >= 1 && days <= 7'">{{task.name}}</div>
模板:
<div ng-repeat="task in tasks | dayFilter: 1 : 7">{{task.name}}</div>
Javascript:
app.filter('dayFilter', function() {
return function(input, startDay, endDay) {
var filterFunction = function (item) {
return item.days >= startDay && item.days <= endDay;
};
return input.filter(filterFunction);
};
});
查看更新的演示小提琴
自定义过滤器示例,您可以根据需要进行修改。
控制者
$scope.search = function (item) {
if ($scope.searchUser == null || $scope.searchUser.trim() == "")
return true;
if (item.FirstName.toLowerCase().indexOf($scope.searchUser.toLowerCase()) != -1 || item.LastName.toLowerCase().indexOf($scope.searchUser.toLowerCase()) != -1 || item.Role.toLowerCase().indexOf($scope.searchUser.toLowerCase()) != -1) {
return true;
}
return false;
};
而不是在您看来
| filter:search
因此,根据您的要求,您可以在控制器中传递尽可能多的参数并修改方法。
//Below code solve my problem.
Date.prototype.getWeek = function () {
// Create a copy of this date object
var target = new Date(this.valueOf());
// ISO week date weeks start on monday
// so correct the day number
var dayNr = (this.getDay() + 6) % 7;
// ISO 8601 states that week 1 is the week
// with the first thursday of that year.
// Set the target date to the thursday in the target week
target.setDate(target.getDate() - dayNr + 3);
// Store the millisecond value of the target date
var firstThursday = target.valueOf();
// Set the target to the first thursday of the year
// First set the target to january first
target.setMonth(0, 1);
// Not a thursday? Correct the date to the next thursday
if (target.getDay() !== 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
// The weeknumber is the number of weeks between the
// first thursday of the year and the thursday in the target week
return Math.ceil((firstThursday - target) / 604800000) - 1; // 604800000 = 7 * 24 * 3600 * 1000
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.