2016-04-14 87 views
6

我在控制器中定義了兩個JSON對象(NotificationsController)。一個包含所有通知,另一個包含最新通知的標識(最近3天)。使用ng-class(AngularJS)搜索JSON對象

格式對象的 「通知」:對象 「最新通知」(t_notifications

[{"0":"1","1":"4","2":"14-APR-16","3":"ALERT 1","ID":"1","ID_USER":"4","DATE":"14-APR-16","NOTIFICATION":"ALERT 1!"},{"0":"2","1":"1","2":"07-APR-16","3":"ALERT 2!","ID":"2","ID_USER":"1","DATE":"07-APR-16","NOTIFICATION":"ALERT 2!"},{"0":"3","1":"1","2":"13-APR-16","3":"ALERT 3!","ID":"3","ID_USER":"1","DATE":"13-APR-16","NOTIFICATION":"ALERT 3!"}] 

格式:(newest_notifications

[{"0":"1","ID_NEWNOTIF":"1"},{"0":"3","ID_NEWNOTIF":"3"}] 

我顯示所有通知如下:

<div class="panel-body" ng-controller="NotificationsCtrl"> 
<table datatable="ng" class="row-border hover"> 
    <thead> 
    <tr> 
     <th><b>ID</b>&nbsp;</th> 
     <th><b>ID_USER</b>&nbsp;</th> 
     <th><b>DATE</b>&nbsp;</th> 
     <th><b>NOTIFICATION</b>&nbsp;</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="data in t_notifications" ng-class="{selected: data.ID == **TO COMPLETE**> 
     <td>{{ data.ID }}</td> 
     <td>{{ data.ID_USER }}</td> 
     <td>{{ data.DATE }}</td> 
     <td>{{ data.NOTIFICATION }}</td> 
    </tr> 
    </tbody> 
</table> 
</div> 

我想知道如何才能在我的表中選擇最新的通知 - 搜索通過JSON對象newest_notifications - 與ng類?

PS:「已選擇」已用藍色背景色定義。

回答

0

您可以使用針對​​的表達式。例如

<tr ng-repeat="data in t_notifications" ng-class="{selected: data.DATE > someDateInThePast}"> 
+0

謝謝您的回答,但我不能完成這樣的任務的方式。我必須通過比較ID來搜索對象。 – Ariana