NG使用过滤器重复比较当前日期



好的,我有一个包含日期列表的对象,我正在这样遍历它:

<select ng-click="monthpicker()" >
<option class="animate-repeat" ng-repeat="returnpicker in monthpicker(alldatesdump)"      value="{{returnpicker.date}}">{{returnpicker.date  | date:'yyyy-MMM' }}</option> 
</select>

使用ng重复此操作将返回以下内容:

<select ng-click="monthpicker()">
  <!-- ngRepeat: returnpicker in monthpicker(alldatesdump) -->
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>
  <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option>

对对象中的每个月如此类推,现在这是因为它为对象中的每一天返回一个月名和一年。好的,我有两个问题:1:我如何过滤结果,使它们只返回每个月名称和年份的一个示例?2:如何设置它,使其仅从当前月份返回?我想只使用AngularJS过滤器来实现这一点,但如果需要的话,我确实有jquery可用!*******更新********这是我的JS文件中的当前范围项:

scope.monthpicker = function(alldatesdump){
var alldatesdump = booking.getalldates();
/*for (var date in alldatesdump){
    if (alldatesdump.hasOwnProperty(date)){
        console.log(date);
    }
}
for (var date in alldatesdump) {
   var obj = alldatesdump[date];
   for (var prop in obj) {
      // important check that this is objects own property 
      // not from prototype prop inherited
      if(obj.hasOwnProperty(prop)){
        console.log(prop + " = " + obj[prop]);
      }
   }
}*/
return alldatesdump;
}; 

以下是我如何使用过滤器仅显示最近两天的订单的示例

.filter('getOrders', function() {
  return function (orders) {
    var filtered_list = [];
    for (var i = 0; i < orders.length; i++) {
      var two_days_ago = new Date().getTime() - 2*24*60*60*1000;
      var last_modified = new Date(orders[i].last_modified).getTime();
      if (two_days_ago <= last_modified) {
        filtered_list.push(orders[i]);
      }
    }
    return filtered_list;
  }
});

DOM看起来像这个

<tr ng-repeat="order in orders|getOrders">

希望这个小提琴能帮助JSFiddle

最新更新