我是AngularJS的新手......我已经构建了一个自定义过滤器,它从午夜开始占用当前秒数,并将其与数据open
/ closed
时间的值进行比较宾语。它工作得很好,并告诉我模型中的商店是否开放。
但是,现在我希望能够允许用户根据商店是打开还是关闭来对数据进行排序。我使用了几个输入复选框来过滤其他类型的数据,例如:
<input type="checkbox" ng-model="query.has_parking" ng-true-value="true" ng-false-value="" > Has Parking
允许用户过滤有停车的商店。
进入的数据的结构时间如下:
{
sunday_open: 720,
sunday_close: 1020,
monday_open: 600,
monday_close: 1320,
tuesday_open: 600,
tuesday_close: 1320,
wednesday_open: 600,
wednesday_close: 1320,
thursday_open: 600,
thursday_close: 1320,
friday_open: 600,
friday_close: 1320,
saturday_open: 600,
saturday_close: 1320
}
所以我的过滤器找到当前日期,然后将其与提供的值进行比较,并返回打开或关闭。
.filter('is_open', function() {
return function(data) {
var currentDay = new Date().getDay();
var currentMSM = (new Date().getHours() * 60) + (new Date().getMinutes());
var open, close;
switch(currentDay)
{
case 0:
open = data.sunday_open;
close = data.sunday_close;
break;
case 1:
open = data.monday_open;
close = data.monday_close;
break;
case 2:
open = data.tuesday_open;
close = data.tuesday_close;
break;
case 3:
open = data.wednesday_open;
close = data.wednesday_close;
break;
case 4:
open = data.thursday_open;
close = data.thursday_close;
break;
case 5:
open = data.friday_open;
close = data.friday_close;
break;
case 6:
open = data.saturday_open;
close = data.saturday_close;
break;
}
// so now I have the open and close time of today at the specified store
// compare it to the current seconds since midnight on the client
return (currentMSM > open && currentMSM < close) ? "Open" : "Closed";
};
})
但是现在我想对复选框输入使用相同的值以允许用户对打开和关闭的商店进行排序,说实话,我甚至不确定从哪里开始。
我知道我无法在ng-model
中使用过滤器,我们将非常感谢任何帮助。