var app = angular.module('testApp',[]);
app.controller('testCtrl', function($scope){
var sortData = {
"accountStatus": "Account status",
"lineStatus": "Line/mobile status",
"accountType": "Account type",
"accountSubType": "Account subtype",
"accountId": "Account #",
"msisdn": "Line/mobile #",
"sim": "SIM/ICCID/CSNID",
"name": "Name"
}
var results = [
{
"msisdn": "7788778606",
"sim": "0",
"firstName": "Tray",
"lastName": "Richardson",
"lineStatus": "Active",
"accountId": "234234328",
"accountStatus": "",
"accountType": "Individual",
"accountSubType": "Postpaid",
"customerId": "1234567890",
"segmentationId": "",
"sourceSystem":""
},
{
"msisdn": "7788778606",
"sim": "1",
"firstName": "David",
"lastName": "Martin",
"lineStatus": "Cancelled",
"accountId": "234234200",
"accountStatus": "",
"accountType": "Business",
"accountSubType": "Prepaid",
"customerId": "0123456789",
"segmentationId": "",
"sourceSystem":""
}
]
<!-- Coding Starts Here -->
sortDataKeys = Object.keys(sortData); // take keys out of the sort object
angular.forEach(results,function(result){ // create a new value in result by concatenating firstname and lastname
result.name = result.firstName+" "+result.lastName;
})
var removeSortDataKeys = []; // Assign a empty array that will get keys to be removed from the sort object
angular.forEach(sortDataKeys, function(key){ // for each sortDataKeys
hasValidValue = false; // Assume it does not have a valid value. so false.
angular.forEach(results, function(result){ // check the result whether it has a valid value
if(result[key]!=""){ // if true, i.e.not equal to empty string
hasValidValue = true; // change the assumption false to true
}
})
if(!hasValidValue)...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.