0

Ich benutze Winkel ng-repeat mit groupBy und orderBy. Was ich versuche zu erreichen, ist die Bestellung von SeatNo ie; 1, 2, 8, 12, aber was Angular gibt mir 1, 12, 2, 8.Angular ng-Reihenfolge wiederholenBy und groupBy nicht richtig bestellen

PS: Ich weiß, dass SeatNo ein String ist und haben versucht, parseInt aber das scheint nicht zu funktionieren

html

<tbody ng-if="::!isOnlyAllSeat" ng-repeat="(key, value) in billRaw | groupBy: 'SeatNo' | orderBy: 'SeatNo' track by key"> 
    <tr class="right bg-darkBlue fg-white"> 
    <td colspan="{{::colSpan}}"> Seat {{key==0?"ALL":key}}</td> 
    <td class="right bill-col-5"><span class="label bg-white fg-black place-right">{{value.length}}</span></td> 
    </tr> 
    <tr ng-repeat="item in value | orderBy: 'ClassCode' " class="fg-darkBlue"> 
    <td class="bill-col-1 middle">{{item.ClassCode}}</td> 
    <td class="text-left bill-col-2 middle"> 
     <span class="">{{item.Name}}</span> 
     <div class="note-tag-list" ng-if="item.Options"> 
     <div class="note-tag-item note-tag" ng-repeat="question in item.Options track by question.Question_ID"> 
      <div ng-repeat="option in question.Options track by option.Option_ID"> 
      <a href class="label info note-tag">{{option.Option}} 
       <small class="price-tag" ng-if="option.ActualPrice !== '0.00'">+{{option.ActualPrice | currency}}</small> 
      </a> 
      </div> 
     </div> 
     </div> 
    </td> 
    <td class="text-left bill-col-5 middle"> 
     <div>{{item.ActualPrice | currency}}</div> 
     <div><small ng-if="item.OptionsTotalActualPrice !== 0">+{{item.OptionsTotalActualPrice | currency}} : Add-on </small></div> 
     <div ng-if="item.DiscountAmt>0"><span class="fg-red">({{(getDiscount(item) | currency)}})</span> : {{((item.ActionTypeID == 1)? item.DiscountAmt+'% OFF':item.CodeName)}}</div> 
     <div ng-if="item.ActionTypeID == 1">{{item.CodeName}}</div> 
    </td> 
    </tr> 
</tbody> 

hier ist mein billRaw Array.

Hinweis - es von SeatNo sortiert

[ 
{"OrderItemID": "329277", 
    "Name": "Mexican Tacos", 
    "Delivered": "0", 
    "ShortName": "MEXICAN TACOS", 
    "Price": "8.0000", 
    "MenuItemID": "2318", 
    "SeatNo": "1", 
    "SequenceNo": "37", 
    "AlcoholCheck": "0", 
    "OStatusID": "2", 
    "Notes": "", 
    "Options": [], 
    "OptionsTotal": 0, 
    "OptionsTotalActualPrice": 0, 
    "ActualPrice": "8.00", 
    "CodeID": 0, 
    "DiscountAmt": 0, 
    "ActionTypeID": 0, 
    "CodeName": 0, 
    "ReductionType": 0, 
    "PayerSeq": "0", 
    "PriceType_ID": "1", 
    "ParentClassName": "Tacos", 
    "NetPrice": 8, 
    "ExtItem_ID": "J9X79NS28M1ZY", 
    "ExtOrderItem_ID": null, 
    "Code": null 
}, 
{ 
    "OrderItemID": "329278", 
    "Name": "Mexican Tacos", 
    "Delivered": "0", 
    "ShortName": "MEXICAN TACOS", 
    "Price": "8.0000", 
    "MenuItemID": "2318", 
    "SeatNo": "2", 
    "SequenceNo": "38", 
    "AlcoholCheck": "0", 
    "OStatusID": "2", 
    "Notes": "", 
    "Options": [], 
    "OptionsTotal": 0, 
    "OptionsTotalActualPrice": 0, 
    "ActualPrice": "8.00", 
    "CodeID": 0, 
    "DiscountAmt": 0, 
    "ActionTypeID": 0, 
    "CodeName": 0, 
    "ReductionType": 0, 
    "PayerSeq": "0", 
    "PriceType_ID": "1", 
    "ParentClassName": "Tacos", 
    "NetPrice": 8, 
    "ExtItem_ID": "J9X79NS28M1ZY", 
    "ExtOrderItem_ID": null, 
    "Code": null 
}, 
{ 
    "OrderItemID": "329276", 
    "Name": "Mexican Tacos", 
    "Delivered": "0", 
    "ShortName": "MEXICAN TACOS", 
    "Price": "8.0000", 
    "MenuItemID": "2318", 
    "SeatNo": "8", 
    "SequenceNo": "36", 
    "AlcoholCheck": "0", 
    "OStatusID": "2", 
    "Notes": "", 
    "Options": [], 
    "OptionsTotal": 0, 
    "OptionsTotalActualPrice": 0, 
    "ActualPrice": "8.00", 
    "CodeID": 0, 
    "DiscountAmt": 0, 
    "ActionTypeID": 0, 
    "CodeName": 0, 
    "ReductionType": 0, 
    "PayerSeq": "0", 
    "PriceType_ID": "1", 
    "ParentClassName": "Tacos", 
    "NetPrice": 8, 
    "ExtItem_ID": "J9X79NS28M1ZY", 
    "ExtOrderItem_ID": null, 
    "Code": null 
}, 
{ 
    "OrderItemID": "329275", 
    "Name": "Mexican Tacos", 
    "Delivered": "0", 
    "ShortName": "MEXICAN TACOS", 
    "Price": "8.0000", 
    "MenuItemID": "2318", 
    "SeatNo": "12", 
    "SequenceNo": "35", 
    "AlcoholCheck": "0", 
    "OStatusID": "2", 
    "Notes": "", 
    "Options": [], 
    "OptionsTotal": 0, 
    "OptionsTotalActualPrice": 0, 
    "ActualPrice": "8.00", 
    "CodeID": 0, 
    "DiscountAmt": 0, 
    "ActionTypeID": 0, 
    "CodeName": 0, 
    "ReductionType": 0, 
    "PayerSeq": "0", 
    "PriceType_ID": "1", 
    "ParentClassName": "Tacos", 
    "NetPrice": 8, 
    "ExtItem_ID": "J9X79NS28M1ZY", 
    "ExtOrderItem_ID": null, 
    "Code": null 
} 
] 

bearbeiten

I billRaw geändert haben, so dass type von SeatNo number ist. aber es funktioniert immer noch nicht

_.forEach($scope.billRaw, function(value,key) { 
    value.SeatNo = parseInt(value.SeatNo); 
}); 
+1

Es ist String-Wert daher so bestellen. Sie müssten es in int konvertieren, wie Sie sagten. Warum funktioniert parsInt nicht? – Zaki

+0

'parseInt' auf 'orderBy' hat keine Wirkung und' parseInt' auf 'groupBy' gibt nur die Array-Indizes 0, 1, 2, 3. –

+0

Wie Sie es analysieren, sollten Sie es auf tatsächlichen JSON-Array tun, bevor Sie tun Sortieren nach. – Zaki

Antwort

0

können Sie versuchen,

$.each(billRaw, function(i) {billRaw[i].SeatNo = parseInt(billRaw[i].SeatNo)}); 

in der Steuerung ausgeführt wird, die die SeatNos zu Zahlen konvertieren. Dann sollte es gut funktionieren.

+0

Ich habe den Typ von SeatNo zu Nummer geändert. aber es funktioniert immer noch nicht –

+0

Versuchen, groupby-Klausel zu entfernen –