javascript - 过滤 AngularJs UI 网格中的对象数组

标签 javascript jquery angularjs

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

例如,我有 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};

关于javascript - 过滤 AngularJs UI 网格中的对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396395/

相关文章:

javascript - Mongoose:CastError:模型 ""的路径 "_id"处的值 ""转换为 ObjectId 失败

javascript - 使用 jQuery 确定单击的左偏移量

jquery - 如何使用jquery为第一个列表项应用事件类

javascript - 无法使用 jQuery 将 <option> 正确添加到 <select>

php - 动态图库

javascript - 如何将现有属性及其值替换为自定义指令并在指令中调用函数

javascript - 带有外部 JSON 文件的 ionic 框架

angularjs - 如何使AngularJS BLOB下载PDF?

javascript - 错误: Property 'getConnection' does not exist on type 'Bluebird<Pool>'

javascript - Jquery UI 拖放和可排序(保留拖动的项目)