2015-04-24 135 views
0

我在另一個對象內部有一個數組對象。所以,在我的html中有兩個嵌套的ng-repeat。我試圖隱藏標籤數據如果行動不是「更改」 爲前。在下面的例子中,最後一行「更改的L3」不應該顯示。如何根據內部數組值對外部數組記錄進行過濾

我的範圍數據:

$scope.groups = 
    [{ 
     "label": "L1", 
     "tabledata": [{ 
         "FIELDNAME": "C1 Entity", 
         "SCREEN": "A", 
         "ORIGINALVALUE": "NA", 
         "ACTION": "Changed", 
         "NEWVALUE": "Something", 
         "TYPEACT": "RB" 

        }, 
        { 
          "FIELDNAME": "C2 Entity", 
          "SCREEN": "A", 
          "ORIGINALVALUE": "NA", 
          "ACTION": "Changed", 
          "NEWVALUE": "SSSS", 
          "TYPEACT": "RB" 

         } 
         ] 

    }, 
    { 
     "label": "L2", 
     "tabledata": [{ 
         "FIELDNAME": "B1 Entity", 
         "SCREEN": "B", 
         "ORIGINALVALUE": "NA", 
         "ACTION": "Changed", 
         "NEWVALUE": "Something", 
         "TYPEACT": "RB" 

        }, 
        { 
         "FIELDNAME": "B2 Entity", 
         "SCREEN": "B", 
         "ORIGINALVALUE": "NA", 
         "ACTION": "Changed", 
         "NEWVALUE": "Something", 
         "TYPEACT": "RB" 

        } 
        ] 

    }, 

    { 
     "label": "L3", 
     "tabledata": [{ 
         "FIELDNAME": "A Entity", 
         "SCREEN": "C", 
         "ORIGINALVALUE": "NA", 
         "ACTION": "Added", 
         "NEWVALUE": "Something", 
         "TYPEACT": "RB" 

        }] 

    }] 

我的HTML在ACTION屬性

<div ng-repeat="group in groups" > 
     <p><b>{{ "Changed " + group.label }}</b> 
       </p> 
     <table class="table table-bordered" > 
      <tbody > 
       <tr > 
        <th width ="20%"><b ng-bind="column1" ></b></th> 
        <th width ="40%"><b>Previous value </b></th> 
        <th width ="40%"><b ng-bind="column3" ></b> </th> 
        <th width ="10%"><b>Action </b></th> 
       </tr> 
       <!-- BEGIN: Inner ngRepeat. --> 
       <tr ng-repeat="endorsedata in group.tabledata | filter :{ACTION : 'Changed'} | orderBy:'FIELDNAME' " > 
        <td ng-init ="showRow = 1">{{ endorsedata.FIELDNAME }}</td> 
        <td>{{ endorsedata.ORIGINALVALUE }}</td> 
        <td>{{ endorsedata.NEWVALUE }}</td> 
        <!-- <td>{{ endorsedata.ACTION }}</td> --> 
       </tr> 
       <!-- END: Inner ngRepeat. --> 
      </tbody> 
     </table> 
    </div> 

我想隱藏標籤,如果有比其他值 '改變'。這如何實現?

Plunker Here

編輯: Plunker鏈接更新。

+1

是的,這並不困難,如果你創建一個過濾器,那麼它的內部使用'$ filter'就可以實現這個功能。非常坦率的。看看'$ filter'源代碼 –

回答

1

在這裏,我們去的話,這應該做你想做的:plunker

基本上,創建了相同的重載一個過濾器的角$filter。然後在每個tabledata裏面使用一個過濾器選項。

如果過濾後的數組與原始數組不同,那麼我們可以安全地說,發現了某種東西。您可以輕鬆修改此以滿足您的確切需求。

該示例顯示瞭如何通過子數組過濾最頂端的數組。

+0

好極了。謝謝 :) –

相關問題