繁体   English   中英

如何使用angularjs在ng-repeat中按属性'today'进行过滤?

[英]How to filter by a property 'today' in ng-repeat using angularjs?

我在阵列上有一个ng-repeat。 每个对象都有一个名为"checkdate"的属性,它只是一个"New Date()"

我希望ng-repeat仅显示今天创建的对象。 我怎样才能做到这一点?

谢谢

$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>   

使用以下内容:

ng-repeat="obj in objects" 

里面:

ng-show="obj.date === Date.now()"

并根据对象日期格式的格式修改Date.now()

这里

或者,您可以执行以下操作:

ng-show="checkDate(obj.date)"

哪里

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM