从Javascript AngularJS中的旧帖子确定新帖子,是否筛选

从Javascript AngularJS中的旧帖子确定新帖子,是否筛选,javascript,php,wordpress,angularjs,Javascript,Php,Wordpress,Angularjs,好的,我正在使用WordPress和JSON API使WordPress成为我的应用程序的后端,现在我正在处理从post获取日期并添加类,如果post是新的或不是新的,我想知道这是一个过滤器的工作,还是只是扩展对象以添加新的属性,基本上是遍历post数组并添加一个属性isNew var today = new Date(); var newMark = new Date(); newMark.setDate(newMark.getDate() - 5); Post.getPosts(5).th

好的,我正在使用WordPress和JSON API使WordPress成为我的应用程序的后端,现在我正在处理从post获取日期并添加类,如果post是新的或不是新的,我想知道这是一个过滤器的工作,还是只是扩展对象以添加新的属性,基本上是遍历post数组并添加一个属性
isNew

var today = new Date();
var newMark = new Date();
newMark.setDate(newMark.getDate() - 5);

Post.getPosts(5).then(function (re) {
  angular.forEach(re.posts, function(post, key){
    var postDate = new Date(post.date);
    console.log(today - postDate < newMark); // lol, I don't have quite a logic here.
    // console.log(postDate - today < today - newMark);
  });
});
但我的逻辑不正确

假设我是从一个类似这样的
Post
服务获得帖子的

$scope.posts = [];
Post.getPosts().then(function(posts){
  $scope.posts = posts;
});
现在在我这样做之前:$scope.posts=posts,我想扩展每个post的属性,添加
isNew

var today = new Date();
var newMark = new Date();
newMark.setDate(newMark.getDate() - 5);

Post.getPosts(5).then(function (re) {
  angular.forEach(re.posts, function(post, key){
    var postDate = new Date(post.date);
    console.log(today - postDate < newMark); // lol, I don't have quite a logic here.
    // console.log(postDate - today < today - newMark);
  });
});
var today=新日期();
var newMark=新日期();
newMark.setDate(newMark.getDate()-5);
getPosts(5)。然后(函数(re){
角度。forEach(重新定位,功能(定位,键){
var postDate=新日期(post.Date);
log(today-postDate
哈哈,今天好像没法思考。

包括

包括


对于所有发布日期在newMark之后的帖子,您希望将属性设置为true,不是吗

$scope.posts=[];
var newMark=new Date(Date.now() - 5 * 24 * 3600 *1000);

Post.getPosts(5)
.then(function (re) {
  // add a property to the model to tell whether is new 
  $scope.posts= re.posts.map(function(post){
    post.isNew=new Date(post.date) >= newMark;
    return post;
  });
});

现在,您可以将
posts
集合绑定到视图,并使用
ngClass
指令和
isNew
属性,例如

您想为所有发布日期在newMark之后的posts设置属性,是吗

$scope.posts=[];
var newMark=new Date(Date.now() - 5 * 24 * 3600 *1000);

Post.getPosts(5)
.then(function (re) {
  // add a property to the model to tell whether is new 
  $scope.posts= re.posts.map(function(post){
    post.isNew=new Date(post.date) >= newMark;
    return post;
  });
});

现在,您可以将
posts
集合绑定到视图中,并使用带有
isNew
属性的
ngClass
指令,例如您在这里需要什么逻辑console.log(今天-postDate