html - 单击按钮后,应在 2 个日期之间过滤数据-Angularjs
问题描述
scope.routeToTxn = function(){
route.reload();
location.path('/tellers/' + routeParams.tellerId + "/cashiers/" + routeParams.cashierId +"/txns/" + scope.formData.currencyCode);
return function( item, startdate,enddate ) {
var filtered = [];
var txnstartDate = Date.parse(txnstartDate);
var txnendDate = Date.parse(txnendDate);
angular.forEach(item, function(item) {
if(item.completed_date > txnstartDate && item.completed_date < txnendDate) {
filtered.push(item);
}
});
return filtered;
};
};
<td class="col-md-2">
from date:
<input id="startDate" sort type="text" datepicker-pop="dd MMMM yyyy" ng-model="txnstartDate" class="form-control" is-open="opened" min="minDate" max="restrictDate"/>
</td>
<td class="col-md-2">
To date:
<input id="endDate" sort type="text" datepicker-pop="dd MMMM yyyy" ng-model="txnendDate" class="form-control" is-open="opened" min="minDate" max="restrictDate"/>
</td>
<td>
<a ng-click="routeToTxn()" class="btn btn-primary">{{'label.button.cashier.showtxn' | translate}} </a>
</td>
单击搜索按钮后,应通过 2 个日期过滤数据:
有两个插入框,需要 2 个日期开始日期和结束日期,点击搜索框后,应看到数据过滤数据
解决方案
检查这个片段你可能想要格式化这些日期,所以当你比较它们时,它们实际上是比较 https://jsfiddle.net/Lt7aP/14764/
此答案中使用的格式化程序 https://stackoverflow.com/a/29774197/8101253
html
<div ng-app ng-controller="Ctrl">
<input ng-model="date1" type="date"></input>
<input ng-model="date2" type="date"></input>
<input type="submit" ng-click="compare(date1, date2)"></input>
{{array}}
</div>
javascript
function Ctrl($scope) {
$scope.array = [new Date("2018-11-06").toISOString().split('T')[0],
new Date("2018-11-07").toISOString().split('T')[0],
new Date("2018-11-09").toISOString().split('T')[0]
];
$scope.compare = function(date1, date2) {
$scope.array
.filter(x => {
console.log(x, date1, date2)
return x > date1 && x < date2
})
.forEach(x => console.log(x));
};
}
推荐阅读
- websphere - 当输入是 .rfh 文件时,如何读取我的流程数据或业务流程中的主文档中的 RFH2 标题
- node.js - 使用打字稿时在 selenium-webdriver 中找不到 WebDriverWait api
- react-native - 我对 firebase.messaging.requestPermission() 有疑问,无论我选择“允许”还是“不允许”,都会导致异常
- django - Django 数据库访问优化:高效创建多对多关系(现有对象之间)
- intellij-idea - 无法在 IntelliJ IDEA 中使用 Lombok 编译项目
- google-cloud-dataflow - GCP:数据流 [无法识别的参数]:来自 cloud-shell 的子网和来自控制台的无效值
- javascript - html中没有定义的函数
- javascript - 在 html 中的 IF/ELSE 上添加 JS 和 CSS 文件
- ruby-2.3 - 检查属于某个类别的所有产品是启用还是禁用?
- php - 有什么办法可以防止这段代码中的路径遍历?