I have an array with empty rows,I have the field "codeOperation" to test if a row is empty or not,this is my table:
The client should fill the table whith data and left the rest of rows empty, what I want is when the client click on the "ADD" boutton only the data will be send and the emoty rows will be deleted.
this is my code:
//function to send the Data
$scope.updateGamme= function(gamme) {
gamme.listElementGammeOf = $scope.finalOperationsList;
$scope.DeleteEmptyRows(gamme.listElementGammeOf);
$http
.put(
baseUrl +
"/gamme/update",
gamme)
.success(
function(gammeModifiee) {
//send the Data and update
.....
}); }
//delete the empty rows
$scope.DeleteEmptyRows = function(listelements){
for (var i = 0; i < listelements.length; i++) {
if (listelements[i].operationCode == "")
listelements.splice(i, 1);
}
What I get as a result with this code, is that per example I get 5 items, my code will remove the rows 3 and 4 the row 2 is not deleted
Is there any problem with my code? Please help me find it.
Thanks for help
'use strict'
you can just check if!listelements[i].operationCode
, it would then show false for undefined, null and empty strings, if you do not have the'use strict'
statement, you will have to check for undefined, null or empty string