2016-03-31 5 views
0

私はagularjsでng-repeatでcontinueを使用しようとしています。それはうまくいきましたが、問題は1つの条件が満たされていてもインデックス値が変更された場合、すなわちインデックスの順序も変更された場合です。 私のコードを以下に示します。正しいindex値を持つangularjsでの使用方法

<tbody> 
    <tr ng-repeat="appointment in rows" ng-if="appointment.isBrightFuture==1"> 
    <td ng-class="{{appointment.isBrightFuture==1?'tdImage':''}}">{{$index+1}} 
     <img ng-if="appointment.isBrightFuture==1" ng-src="img/brightfuture_logomedium.png"> 
    </td> 
    <td>{{appointment.date}}</td> 
    <td>{{appointment.time}}</td> 
    <td>{{appointment.specialtyId=="5"?'Pediatrics':appointment.specialty}}</td> 
    <td>{{appointment.physicianName}} 
     <br/>{{appointment.orgName}}</td> 
    <td>{{appointment.reason!="null"?appointment.reason:''}}</td> 
    <td> 
     <img ng-if="hasAppointmentPrivilege()" src="img/edit.png" ng-click="editPastAppointment($index)" /> 
    </td> 
    <td> 
     <img ng-if="hasAppointmentPrivilege()" src="img/cancel.png" ng-click="deletePastAppointment($index)" /> 
    </td> 
    </tr> 
</tbody> 

enter image description here

+0

あなたは絵が見えるように何を期待していますか? –

+0

1,2,3で正しい順序が欲しい – user3189828

答えて

2

代わりのNGを-場合は使用して行の1つを表示するようなときには、あなたはそれを表示する前に、配列をフィルタリングする必要があります。その問題はあなたのものとは逆ですが、$ indexは元の配列ではなく、フィルターされた配列内の現在の要素のインデックスになります。だから、むしろそのインデックスよりも要素自体を受け入れるように機能をリファクタリングする必要があります

<tr ng-repeat="appointment in rows | filter:hasBrightFuture"> 
    <td class="tdImage">{{$index+1}} 
     <img src="img/brightfuture_logomedium.png" /> 
    </td> 
    <td>{{appointment.date}}</td> 
    <td>{{appointment.time}}</td> 
    <td>{{appointment.specialtyId=="5"?'Pediatrics':appointment.specialty}}</td> 
    <td>{{appointment.physicianName}} 
     <br/>{{appointment.orgName}}</td> 
    <td>{{appointment.reason!="null"?appointment.reason:''}}</td> 
    <td> 
     <img ng-if="hasAppointmentPrivilege()" src="img/edit.png" ng-click="editPastAppointment(appointment)" /> 
    </td> 
    <td> 
     <img ng-if="hasAppointmentPrivilege()" src="img/cancel.png" ng-click="deletePastAppointment(appointment)" /> 
    </td> 
</tr> 

そして、あなたのコントローラで:

$scope.hasBrightFuture = function(appointment) { 
    return appointment.isBrightFuture === 1; 
} 
関連する問題