[英]How to filter by a property 'today' in ng-repeat using angularjs?
I have an ng-repeat on an array. 我在阵列上有一个ng-repeat。 Each object has a property called
"checkdate"
which is just a "New Date()"
. 每个对象都有一个名为
"checkdate"
的属性,它只是一个"New Date()"
。
I want the ng-repeat
to only show objects created TODAY. 我希望
ng-repeat
仅显示今天创建的对象。 How can I do this? 我怎样才能做到这一点?
Thanks 谢谢
$scope.list1 = [
{name: "item1", checkdate: '2016-03-04T09:25:57.882Z'},
{name: "item2", checkdate: '2016-03-05T09:25:57.882Z'},
{name: "item3", checkdate: '2016-03-06T09:25:57.882Z'}];
var curDate = new Date();
var y = curDate.getFullYear();
var m = curDate.getMonth() + 1;
if (m < 10) {
m = '0' + m;
}
var d = curDate.getDate();
if (d < 10) {
d = '0' + d;
}
$scope.curDate = y + '-' + m + '-' + d;
... ...
<div ng-repeat="item in list1 | filter:{checkdate: curDate}">
{{item.name}} - {{item.checkdate}}
</div>
Use the following: 使用以下内容:
ng-repeat="obj in objects"
and inside: 里面:
ng-show="obj.date === Date.now()"
And modify Date.now()
according to the format of your objects date format. 并根据对象日期格式的格式修改
Date.now()
。
Or you can do the following: 或者,您可以执行以下操作:
ng-show="checkDate(obj.date)"
where 哪里
checkdate(date){
var todaysDate = new Date();
//call setHours to take the time out of the comparison
if(date.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0));
{
return true
} else { return false}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.