在 AngularJS UI 网格中,我接收 JSON 对象并将其绑定(bind)到网格。现在我想根据某些复选框中的多个条件过滤行。
例如,我有 3 个时间复选框:
10:00 - 12:00 -- checkbox
14:00 - 18:00 -- checkbox
20:00 - 23:00 -- checkbox
如果用户点击10:00 - 12:00
和14:00 - 18:00
复选框,则应根据这些时间过滤该行。
$scope.filterGrid = function(value) {
for (int i = 0; i <= $scope.gridApi.grid.columns[2].rows.entity.length(); i++) {
// I put one condition here as an example, but in my code all of the conditions
// are included
if ($scope.gridApi.grid.columns[2].rows.entity[i].time >= "14:00" &&
$scope.gridApi.grid.columns[2].rows.entity[i].time <= "18:00") {
$scope.gridApi.grid.columns[2].filters[0]={term:value};
}
}
};
在我的代码中,我可以获取对象在时间范围内包含的内容,但是当我将对象添加到网格中时,我只能获取最后添加的对象。例如,如果我有 4 个对象,则网格始终显示第 4 个对象。
我认为我不是添加对象,而是覆盖它们。我该如何解决这个问题?
感谢您的帮助。
最佳答案
你必须改变:
$scope.gridApi.grid.columns[2].filters[0]={term:value};
至:
$scope.gridApi.grid.columns[2].filters[i]={term:value};
关于javascript - 过滤 AngularJs UI 网格中的对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396395/