2016-07-01 20 views
0

$ .. balanceChangeを使用して配列を並べ替えるのを手伝ってください。それは応答の小さな部分です。Jsonpath並べ替え配列

私はSoapUIでアサーションが必要です。

 
{ 
     "id": 182, 
     "name": "49899 Consol Sick w S&S Pattern", 
     "eventDefinition":  { 
     "id": 111, 
     "name": "49899 Consol Sick w S&S Pattern", 
     "shortName": null, 
     "displayName": "49899 Consol Sick w S&S Pattern", 
     "active": true, 
     "group": null, 
     "lowerThresholdAmount": 0, 
     "upperThresholdAmount": 0, 
     "lowerThresholdDayAmount": null, 
     "upperThresholdDayAmount": null, 
     "amountUnit": null, 
     "exceptionType": null, 
     "comment": null, 
     "paycode": null, 
     "paycodeAmountType": null, 
     "usedType": null, 
     "punchType": null, 
     "type": {"name": "pattern"}, 
     "extendedData": null, 
     "dayBased": false 
     }, 
     "policyDefinition":  { 
     "id": 404, 
     "name": "49899 Consolidated Sick w S&S plc467381724319" 
     }, 
     "ruleDefinition":  { 
     "id": 604, 
     "name": "WR467381724319" 
     }, 
     "pointTransaction":  { 
     "id": 313, 
     "name": "Attendance Points 1", 
     "employeeId": 385, 
     "balanceChange": 5, 
     "typeCategory": "POINT", 
     "applyDate": "2016-04-28T00:00:00" 
     }, 
     "type": {"name": "pattern"}, 
     "employeeId": 385, 
     "applyDate": "2016-04-28", 
     "eventTime": "00:00:00", 
     "amount": null, 
     "dayAmount": null, 
     "updatedByUserId": 12, 
     "isSystem": true 
    } 
+1

?もっと説明していただけますか? – Anton

+0

$ .. balanceChangeを実行すると[9.0、8.0、9.0、8.0、8.0、8.0、6.0、5.0]になります。しかし時にはこのシーケンスが変わり、[8.0,9.0,9.0,8.0,8.0,8.0,6.0,5.0]を得ることができます。私はbalanceChangeによってこの配列をソートする必要があります –

+0

だから、簡単な方法はアンダースコアを使用することです。あなたが助けてくれるかもしれませんが、もし私がコードを書き直そうとしたら、ちょうど私に知らせてください – Anton

答えて

0

underscore.js libを試してください。あなたはそれ(ID、名前、またはオブジェクトによって)ソートするにはどうすればよいPlunker

var arr = [ 
    { 
    "id": 182, 
    "name": "49899 Consol Sick w S&S Pattern" 
}, 
{ 
    "id": 183, 
    "name": "49900 Consol Sick w S&S Pattern" 
},{ 
    "id": 184, 
    "name": "49901 Consol Sick w S&S Pattern" 
},{ 
    "id": 185, 
    "name": "49902 Consol Sick w S&S Pattern" 
},{ 
    "id": 186, 
    "name": "49903 Consol Sick w S&S Pattern" 
},] 


console.log(_.sortBy(arr, 'id')) 

か、単に最も簡単な(plunkerの例)

var data = [9.0, 8.0, 9.0, 8.0, 8.0, 8.0, 6.0, 5.0] 
console.log(data.sort()); 
+0

OP指定彼はSoapUI、 JSインタープリタを持たない。 – SiKing