I have an array like object named vm.comparisonThumbnail.list that contains 40 indexed properties. And i grouped the value inside based on their unique id's into array using lodash _.groupBy. The result contains an object with 6 arrays inside. Note: I'm using angularjs dnd(drag and drop) to arrange the sequence.
Here is my code:
function arrangeSequence(key, index) {
var myArray = vm.comparisonThumbnail.list;
console.log("myArray");
console.log(myArray);
var groupedArray = _.groupBy(myArray, 'courseContentId');
console.log(groupedArray);
var keyArray = groupedArray[key];
var result = vm.comparisonThumbnail.list.map(v =>
v.courseContentId).sort();
var filter = result.filter(function (value, indexx, array) { return
array.indexOf(value) == indexx; });
keyArray.splice(index, 1);
//
var originalSelectedId =
angular.copy(vm.comparisonThumbnail.selected.id);
var currentIndex = _.findIndex(vm.comparisonThumbnail.list, 'id',
originalSelectedId);
var newArray = [];
filter.forEach(keyz => {
newArray = newArray.concat(groupedArray[keyz]);
});
vm.comparisonThumbnail.list = newArray;
}
The problem here is that i can only arrange the sequence properly on the first grouped array. Here is the data inside the first.
[
>0:{courseContentId: 471, fileName: "Testing"},
>1:{courseContentId: 471, fileName: "Testing2"},
>2:{courseContentId: 471, fileName: "Testing3"},
>3:{courseContentId: 471, fileName: "Testing4"},
>4:{courseContentId: 471, fileName: "Testing5"},
]
I grouped them based on courseContentId. And if i tried to arrange the sequence on the second array and so on it won't arrange properly.
Comments
Post a Comment