Within my angularjs application, I am working with a collection of objects.
$scope.itemsList = [
{
"setupId": "T_2893",
"name" : "abc"
},
{
"setupId": "LBT826",
"name" : "xyz"
},
{
"setupId": "LBT1252",
"name" : "pqr"
},
{
"setupId": "G1252",
"name" : "dwr"
}
]
When invoking the $scope.changeOreder(1, 3) function, the objective is to rearrange the objects based on the previous and next index. The updated list should appear as follows:
$scope.itemsList = [
{
"setupId": "T_2893",
"name" : "abc"
},
{
"setupId": "LBT1252",
"name" : "pqr"
},
{
"setupId": "G1252",
"name" : "dwr"
},
{
"setupId": "LBT826",
"name" : "xyz"
}
]
If calling $scope.changeOreder(2, 0)
, the new order will be as follows:
$scope.itemsList = [
{
"setupId": "G1252",
"name" : "dwr"
},
{
"setupId": "T_2893",
"name" : "abc"
},
{
"setupId": "LBT1252",
"name" : "pqr"
},
{
"setupId": "LBT826",
"name" : "xyz"
}
]
While attempting to implement the $scope.changeOrder function, I have experimented with various approaches such as creating a backup of the object at the prevIndex
, then removing the object at prevIndex
in order to insert the backed-up object at newIndex
. However, due to deleting the object, the newIndex
becomes invalid within the current list!!! Despite trying different methods, the final list does not get ordered in the expected manner. Any assistance in resolving this issue would be greatly appreciated.