please see this dropdown



我有一个要显示为ng-option的数组列表。由于PCBU有时会包含列表中的所有值,有时包含两个PCBUse(用逗号分隔)。检出JSON响应,第一个PCBU的值为“ NKSMO,NNOWR”。我试图在ng选项中显示为两个单独的PCBU选项“ NKSMO”和“ NNOWR”,现在将其显示为一个“ NKSMO,NNOWR”选项。

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
            }
         ],


$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>




我尝试使用split方法将逗号与数组分开,但它对我不起作用。

最佳答案

我没有完全回答您的问题,我将所有PCBU(逗号分隔)提取到一个数组中,可以轻松地将其传递给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);

10-01 01:26