我的过滤器出现问题,我解释说,当我的程序启动时,我会重新启动表格(重复)
但 第一次
在控制台日志中()当我第一次初始化时,它会让我" item undifined"然后它直接返回过滤器" myfilter"它向我展示了对象,
我不明白为什么我有"物品未经加工?"
我希望它能同时完成所有这一切,第二个问题是链接到第一个问题,当我按下一个datepicker字段时,它会让我发出2个警告,因此它会调用两次过滤器
这是我的过滤器代码
routeAppControllers.filter("myfilter", function($filter) {
return function(items, from, to) {
const testFrom = Date.parse(from);
const testTo = Date.parse(to);
if (!testFrom){
// console.log('Not valid');
from = moment();
}
if (!testTo){
to = moment('2500-01-01');
}
const valids = items.reduce((acc,val) => {
var st = val.DATE_AGENDA;
// alert(val.DATE_AGENDA);
/*
var res = st.substring(0, 10);
var res = res.split("-");
var res1= res[2]+'-'+res[1]+'-'+res[0];
alert(res);
var dt = new Date(res1);
*/
const date = moment(val.DATE_AGENDA);
if(date.isSameOrAfter(from) && date.isSameOrBefore(to))
acc.push(val)
return acc;
},[]);
return valids;
};
});
这是我的2个输入
<input type="text" placeholder="Date debut" class="form-control" ng-click="open1()" uib-datepicker-popup ng-model="startDate" show-button-bar="false" is-open="popup1.opened" datepicker-options="dateOptions" ng-change="filter()" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
<input type="text" placeholder="Date fin" class="form-control" ng-click="open2()" uib-datepicker-popup ng-model="endDate" show-button-bar="false" is-open="popup2.opened" datepicker-options="dateOptions" ng-change="filter()" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open2()"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
这是我的ng-repeat
<tr ng-repeat="data in filtered = (myData | filter:search | orderBy : predicate :reverse | myfilter: startDate: endDate) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
我让我更有帮助
http://plnkr.co/edit/6RuUjkON4HaXE3EHg7bn?p=preview
如果有人可以帮助我
提前致谢