Viraj
Viraj

Reputation: 27

Separate the value from array that is coming as one but seperated by comma

please see this dropdown

I have one list of the array that I am displaying as ng-option. all the value in the list that is coming as PCBU sometimes contains two PCBUseparated by comma. checkout JSON response, the value of first PCBU its "NKSMO,NNOWR". I am trying to display that as two seperate PCBU option "NKSMO" and "NNOWR" in the ng-option, right now its showing as one "NKSMO,NNOWR" option.

JSON Response

"statusType":"success",
"statusMsg":{  
    "approvals":{  
         "inProgress":[  
            {  
               "projectStatus":"Pending Decision",
               "pcbu":"NKSMO,NNOWR",
               "statusUpdatedDate":"2019-07-31 15:04:30",
               "requestType":"PORCHNGEREQ",
               "folderStatus":false,
               "projectName":"TEST POR CAHNGE REQ",
               "priority":"NORMAL",
               "projectId":24324
            },
            {  
               "projectStatus":"Pending Decision",
               "pcbu":"NKSMO",
               "statusUpdatedDate":"2019-05-24 09:41:36",
               "requestType":"PORCHNGEREQ",
               "folderStatus":false,
               "projectName":"Mobile Test - Jack - POR 1",
               "priority":"NORMAL",
               "projectId":23351
            }
         ],
$scope.pcbuSelect = "";

$scope.loadRequests=function(requestType){
    var jsonObj = {
      "userId":$scope.userId,
      "requestType":requestType
    };
    workflowProjFundFactory.getApprovalRequest(jsonObj)
    .success(function(data, status) {
        if (JSON.stringify(data.statusType).indexOf("success") > -1) {            
            var allrequests = data.statusMsg;
            $scope.inProgressDataList=$scope.inProgressDataList
                .concat(allrequests.approvals.inProgress) ;
            $scope.pcbuList = $scope.inProgressDataList
                .concat(allrequests.approvals.pcbu);
        }
    }
}
<label for="PCBU" class="control-label-left typeAllOptionStyling">PCBU</label>
<div class="selecteddiv" style="margin-right: 1%;">
    <select ng-model="pcbuSelect" name="pcbuSelect"
            ng-options="removeUndefined(item.pcbu) for item in pcbuList | unique:'pcbu'"></select>
</div>

I have tried using the split method to separate the comma from the array but it does not work for me.

Upvotes: 1

Views: 70

Answers (1)

sumit
sumit

Reputation: 15464

I didn't exactly got your question , i have extracted all PCBU (comma seperated) to one single array which can be easily passed to ng-options

let json={
    "statusType": "success",
    "statusMsg": {    
    	"approvals": {
    	    "inProgress": [{
                "projectStatus": "Pending Decision",
                "pcbu": "NKSMO,NNOWR",
                "statusUpdatedDate": "2019-07-31 15:04:30",
                "requestType": "PORCHNGEREQ",
                "folderStatus": false,
                "projectName": "TEST POR CAHNGE REQ",
                "priority": "NORMAL",
                "projectId": 24324

             },
             {
                "projectStatus": "Pending Decision",
    		    "pcbu": "NKSMO",
                "statusUpdatedDate": "2019-05-24 09:41:36",
                "requestType": "PORCHNGEREQ",
                "folderStatus": false,
                "projectName": "Mobile Test - Jack - POR 1",
                "priority": "NORMAL",
                "projectId": 23351
             }
            ]
        }
    }
}

let dropdown=(json.statusMsg.approvals.inProgress.map(p=>p.pcbu.split(",")).flat());
let unique_dd=[...new Set(dropdown)]; 
console.log(unique_dd);

Upvotes: 1

Related Questions