我正在尝试通过键入日期范围来过滤包含时间戳的列表例如:的jsfiddleHTML<div ng-app="tst">
<div ng-controller="MyController">
<table>
<tr>
<td>From: <input ng-model="query.date1" type="text" placeholder="" />
</td>
<td>To: <input ng-model="query.date2" type="text" placeholder="" />
</td>
</tr>
<tr ng-repeat="order in orders |filter:query">
<td>{{order.date1 * 1000 | date:'dd-MM-yyyy'}}</td>
<td>{{order.date2 * 1000 | date:'dd-MM-yyyy'}}</td>
</tr>
</table>
</div></div>JavaScript的var nameSpace = angular.module('tst',[]);nameSpace.controller('MyController', function MyController($scope) {
$scope.orders = [
{
"date1":"1306487800",
"date2":"1406587800"
},
{
"date1":"1196487800",
"date2":"1406597800"
}]});我希望能够用值填充“发件人”字段:27-05-2010并且“ To”字段的值为:29-07-2015并仅获取该范围内的记录。(示例中的第一条记录)。谢谢分配阿维
3 回答
开心每一天1111
TA贡献1836条经验 获得超13个赞
对于时间操纵,我强烈建议使用诸如momentJS之类的库;使用momentJS和现代浏览器,可以以非常声明的方式实现:
.filter('dateRange', function() { return function(items, startDate, endDate) { //an undefined startDate is converted to the beginning of time startDate = startDate || 0; const granularity = null // can be 'days', ... see momentJS doc //you need support for array.prototype.filter and arrow functions; i.e. IE sucks/needs a polyfill return items.filter(item => moment(item).isBetween(startDate, endDate, granularity, '[]')); }}
- 3 回答
- 0 关注
- 654 浏览
添加回答
举报
0/150
提交
取消