Angular ng-repeat orderBy和groupBy没有正确排序

时间:2016-07-05 10:43:42

标签: javascript arrays angularjs angularjs-ng-repeat angularjs-orderby

我使用ng-repeatgroupByorderBy一起使用角度parseInt。 我想要实现的是通过SeatNo订购,即; 1,2,8,12,但Angular给我的是1,12,2,8。

PS :我知道SeatNo是一个字符串并尝试了<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> 但似乎无法正常工作

HTML

billRaw

这是我的[ {"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 } ] 数组。

注意 - 按SeatNo排序

type

修改

我修改了billRaw,因此SeatNo的number_.forEach($scope.billRaw, function(value,key) { value.SeatNo = parseInt(value.SeatNo); }); 。但它仍然无法运作

{{1}}

1 个答案:

答案 0 :(得分:0)

您可以尝试运行

geom_point

在控制器中,它将SeatNos转换为数字。然后它应该工作正常。