繁体   English   中英

在AngularJs UI Grid中过滤对象数组

[英]Filter array of object in AngularJs UI Grid

在AngularJS UI Grid中,我接收JSON对象并将其绑定到网格。 现在我想根据一些复选框中的多个条件来过滤行。

例如,我有3个时间复选框:

10:00 - 12:00 -- checkbox
14:00 - 18:00 -- checkbox
20:00 - 23:00 -- checkbox

如果用户单击10:00 - 12:0014: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};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM