簡體   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