我正在尝试使用lodash对API响应数据进行排序。我的API是:https://www.clickpost.in/api/v2/track-order/?username=testuser&key=2e9b19ac-8e1f-41ac-a35b-4cd23f41ae17&waybill=3515341&cp_id=10
API数据如下:
{
"result": {
"3515341": {
"latest_status": {
"clickpost_status_code": 8,
"remark": "Delivered on 03 Nov 16 - Signed by sign",
"timestamp": "2016-11-03 08:10:56+00:00",
"location": "MUMBAI, MUMBAI",
"clickpost_status_description": "Delivered",
"status": "Delivered"
},
"valid": true,
"scans": [
{
"clickpost_status_code": 5,
"remark": "Arrived in",
"timestamp": "2016-10-27 22:19:18+00:00",
"location": "DELHI, DELHI",
"clickpost_status_description": "InTransit",
"status": "In Transit to"
},
{
"clickpost_status_code": 5,
"remark": "In Transit to",
"timestamp": "2016-10-27 22:18:57+00:00",
"location": "DELHI, DELHI",
"clickpost_status_description": "InTransit",
"status": "In Transit to"
},
{
"clickpost_status_code": 6,
"remark": "Out For Delivery",
"timestamp": "2016-10-31 13:29:24+00:00",
"location": "MUMBAI, MUMBAI",
"clickpost_status_description": "OutForDelivery",
"status": "Out For Delivery"
},
{
"clickpost_status_code": 1,
"remark": "OrderPlaced",
"timestamp": "2016-10-26 16:33:23.650953+00:00",
"location": "None",
"clickpost_status_description": "OrderPlaced",
"status": "OrderPlaced"
},
{
"clickpost_status_code": 8,
"remark": "Delivered on 03 Nov 16 - Signed by sign",
"timestamp": "2016-11-03 08:10:56+00:00",
"location": "MUMBAI, MUMBAI",
"clickpost_status_description": "Delivered",
"status": "Delivered"
},
{
"clickpost_status_code": 5,
"remark": "Arrived at",
"timestamp": "2016-10-29 12:31:05+00:00",
"location": "MUMBAI, MUMBAI",
"clickpost_status_description": "InTransit",
"status": "Arrived at"
},
{
"clickpost_status_code": 5,
"remark": "In Transit to",
"timestamp": "2016-10-28 00:15:32+00:00",
"location": "MUMBAI, MUMBAI",
"clickpost_status_description": "InTransit",
"status": "In Transit to"
},
{
"clickpost_status_code": 4,
"remark": "Picked up and Booking processed",
"timestamp": "2016-10-27 22:15:13+00:00",
"location": "SOUTH DELHI, DELHI",
"clickpost_status_description": "PickedUp",
"status": "Picked up and Booking processed"
}
]
}
},
"meta": {
"success": true,
"message": "SUCCESS",
"status": 200
}
}
js文件是:
var username="testuser";
var key ="2e9b19ac-8e1f-41ac-a35b-4cd23f41ae17";
var waybill ="3515341";
var cp_id = "10";
$http({
url: "https://www.clickpost.in/api/v2/track-order/",
params: {
username:username,
key:key,
waybill:waybill,
cp_id:cp_id
},
method: 'GET'
}).then(function(response){
$scope.track = response.data;
var sortData = response.data;
sortData = _.sortBy(sortData, ['clickpost_status_code']);
console.log(sortData);
$log.info(response);
// console.log(response.data);
}, function error(response) {
// $scope.error = response.data;
$scope.error = "wrong";
$log.info(response);
});
需要根据“clickpost_status_code”获取数据,以便显示我的跟踪订单状态。请建议我怎么做。
答案 0 :(得分:0)
假设response.data是有效载荷:
setMovementMethod(LinkMovementMethod.getInstance());