2016-04-14 14 views
6

コントローラに2つのJSONオブジェクトが定義されています(NotificationsController)。 1つはすべての通知で、もう1つは最新の通知のIDのみ(過去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-classで検索して、最新の通知のみを自分のテーブルで選択する方法を知りたいですか?

PS: "選択済み"はすでに青色の背景色で定義されています。

答えて

3

だけ


... ng-class="{'selected': (newest_notifications | filter : { ID_NEWNOTIF: data.ID } : true).length !== 0 }" 

filter厳しいフィドル使用 - https://jsfiddle.net/dyxf5xqj/

+0

ありがとうございます:D完璧に動作しています! – Ariana

+0

それは素晴らしいです。乾杯! – potatopeelings

0

​​に対して式を使用できます。例えば

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

は、あなたの答えをありがとう、私は、このようなタスクをそのように達成することはできません。 IDを比較してオブジェクトを検索する必要があります。 – Ariana

関連する問題