好的,我有一个包含日期列表的对象,我像这样遍历它:
<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-repeat 返回以下结果:
<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!********UPDATE**************这是我的 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 http://jsfiddle.net/zargyle/kMksx/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)