簡體   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