我有这样的模特:
{
"TaskDate": "2015-01-04T00:00:00",
"TimesheetList": [
{
"WorkItemId":24,
"ProjectId":3,
"ProjectName":"Hello world",
"UserId":12,
"UserName":"Anatoliy Svetliakov",
"Date":"2015-01-04T22:00:00",
"Task":"#34 : New task test",
"TimeWorked":2,
"Note":null,
"InProgress":false
}
]
}
此数据显示在带无限滚动的表格中。我需要创建自定义过滤器,该过滤器将按Name
和/或Data(from-to)
过滤数据。请告诉我如何做到这一点。我已创建了功能,但它无法正常工作。
.filter('tsFilter', function() {
return function(model, filter) {
var filtered = [];
if (model != null) {
for (var i = 0; i < model.length; i++) {
filtered[i] = model[i];
}
}
if (filter != null) {
if (filter.UserId != null) {
for (i = 0; i < filtered.length; i++) {
for (var j = 0; j < filtered[i]['List'].length; j++) {
if (filtered[i].List[j].UserId != filter.UserId) {
filtered.splice(j, 1);
j--;
}
}
}
}
}
for (i = 0; i < filtered.length; i++) {
if (filtered[i].List.length == 0) {
filtered.splice(i, 1);
i--;
}
}
return filtered;
};
})
页面表显示为:
<div class="timesheet-table-container">
<table class="table-timesheet" id="table-body" infinite-scroll-immediate-check="false" infinite-scroll="loadMore()" infinite-scroll-distance="1">
<tbody ng-repeat="item in model | tsFilter: filter | limitTo: limits track by $index">
<tr class="timesheet-day-block">
<td colspan="6">
<span class="timesheet-date">{{item.TaskDate | dateFilter}}</span>
</td>
</tr>
<tr class="timesheet-table-rows" ng-repeat="list in item.List" ng-form="logged">
<td>{{list.ProjectName}}</td>
<td>{{list.UserName}}</td>
<td>{{list.Date | date: 'dd/MM/yyyy'}}</td>
<td>{{list.Task}}</td>
<td>{{list.TimeWorked}}</td>
<td>
<span style="width: 85%">{{list.Note}}</span>
<button class="active-delete-button" ng-click="removeTask(list)" style="display: inline-block; float:right">вњ–</button>
</td>
</tr>
</tbody>
</table>
</div>