Hi In my Controller from Server I am getting a JSON String
$scope.unsorted=data;
And the data looks like
[
{
"configId": 116,
"configName": "LAND_LINE",
"configFieldses": [
{
"FieldId": 784,
"FieldName": "engine.form.1",
"values": [
{
"keyname": "formName",
"value": "Account Number",
"id": 3068
},
{
"keyname": "formValuePosition",
"value": "right",
"id": 3069
}
]
},
{
"FieldId": 783,
"FieldName": "engine.form.0",
"values": [
{
"keyname": "formName",
"value": "Amount",
"id": 3074
},
{
"keyname": "formValuePosition",
"value": "right",
"id": 3075
},
{
"keyname": "regexGazatteer",
"value": "Total Charges :",
"id": 3076
}
]
},
{
"FieldId": 785,
"FieldName": "engine.table2",
"values": [
{
"keyname": "regexTableHeaderStart",
"value": null,
"id": 3079
},
{
"keyname": "regexTableBodyEnd",
"value": null,
"id": 3080
},
{
"keyname": "tableName",
"value": "invoice",
"id": 3078
}
]
}
]
}
]
I want to sort the configFieldses array based on FieldId and also the values array in each configFieldses based on id. So the JSON should looks like
[
{
"configId": 116,
"configName": "LAND_LINE",
"configFieldses": [
{
"FieldId": 783,
"FieldName": "engine.form.0",
"values": [
{
"keyname": "formName",
"value": "Amount",
"id": 3074
},
{
"keyname": "formValuePosition",
"value": "right",
"id": 3075
},
{
"keyname": "regexGazatteer",
"value": "Total Charges :",
"id": 3076
}
]
},
{
"FieldId": 784,
"FieldName": "engine.form.1",
"values": [
{
"keyname": "formName",
"value": "Account Number",
"id": 3068
},
{
"keyname": "formValuePosition",
"value": "right",
"id": 3069
}
]
},
{
"FieldId": 785,
"FieldName": "engine.table2",
"values": [
{
"keyname": "tableName",
"value": "invoice",
"id": 3078
}
{
"keyname": "regexTableHeaderStart",
"value": null,
"id": 3079
},
{
"keyname": "regexTableBodyEnd",
"value": null,
"id": 3080
}
]
}
]
}
]
What I have tried is first sort the parent array and then the child arrays.
var sortedfieldses = orderByFilter($scope.unsorted.configFieldses, '+FieldId');
But then How to remoive the old array from unsorted config and add the new to unsorted. And also how to loop through each and then sort it?
What is the best way?