我正在试图制作一个过滤器,它只会显示一月份某月的json条目。但是,我遇到了麻烦。我尝试设置1月和2月的变量,然后将输入设置为大于1月的第一个日期并且小于2月的第一个日期,但这种方法无效。任何帮助将不胜感激。angular.js按月过滤
这里是我的html:
<div ng-app="myApp" ng-controller="Catalog">
<div class="bg" ng-repeat="book in books">
<div ng-show=" book.doc.date | mydate" >
<div class="date">{{book.doc.date}}</div>
<div class="title">{{book.doc.title}}</div>
<div class="quote">{{book.doc.quote}}</div>
<div class="attribution">-{{book.doc.attribution}}</div>
<div class="textt">{{book.doc.text}}</div>
<div style="height:10px"></div>
</div>
</div>
<div class="bg" ng-repeat="book in books ">
<div ng-click="showInfo = !showInfo" ng-show=" book.doc.date | January">
<div class="date">{{book.doc.date}}</div>
<div class="title">{{book.doc.title}}</div>
<div class="quote" ng-show="showInfo">{{book.doc.quote}}</div>
<div class="attribution" ng-show="showInfo">- {{book.doc.attribution}}</div>
<div class="textt" ng-show="showInfo">{{book.doc.text}} </div>
<div style="height:10px"></div>
</div>
</div>
</div>
和我的JS:
var myApplication = angular.module('myApp', ['ngColorThis']);
myApplication.controller("Catalog", function ($scope) {
$scope.books = books;
$scope.showInfo = false;
})
.filter('mydate', function() {
return function(input) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0, so always add + 1
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
return (input == today)
}
})
.filter('past', function() {
return function(input) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0, so always add + 1
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
return (input)
}
})
.filter('January', function() {
return function(input) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0, so always add + 1
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
var jan = 00 + "/" +00;
var feb = 01 + "/" + 00;
return (input > jan && input < feb)
}
});
而且,这里是我的项目的完整plunker。