0

below is part of my JSON response coming from an API

    {
        "totalCount": 2,
        "customAttributes": [
            {
                "objectType": "OWNER",
                "atrributeId": 215,
                "attributeName": "DATELICENSEFIRSTISSUED",
                "attributeDisplayName": "DATE LICENSE FIRST ISSUED",
                "dataType": "DATE",
                "inputValues": [],
                "isGridEligible": "true",
                "isInvoiceEligible": "false"
            },
            {
                "objectType": "LOCATION",
                "atrributeId": 217,
                "attributeName": "DONOTRENEW",
                "attributeDisplayName": "DO NOT RENEWS",
                "dataType": "Value List",
                "inputValues": [
                    {
                        "id": 5,
                        "value": "VEHICLELISTREQUIRED"
                    },
                    {
                        "id": 6,
                        "value": "STATESWITHRECIPROCITY"
                    }
                ],
                "isGridEligible": "true",
                "isInvoiceEligible": "false"
            }        
        ]
    }

Here, I am binding customAttributes as grid data.

    this.customFieldsService.getCustomFields(this.columnList, this.pageNumber, this.pageSize, null).subscribe(res => {
      if(res){
        this.cfData = res;    
        this.gridData = {
            data: this.cfData.customAttributes,
            total: this.cfData.totalCount
        }
      }      
    });

Here, my problem is with inputValues column, which comes as an array of objects. I need to convert it to comma seaparated values and then bind to grid data like

  "inputValues": ["VEHICLELISTREQUIRED" "STATESWITHRECIPROCITY"]

I can ignore the "id" property as we are not using it at angular side. I tried using join method but not able to solve it within the nested array. Please suggest. Thanks.

1 Answer 1

1

In typescript it can be done with:

const joined: string = customAttribute.inputValues
    .map(x => x.value)           //  [{value: 'VEHICLELISTREQUIRED'}, {value: 'STATESWITHRECIPROCITY'}]
    .join(' ')                   //  "VEHICLELISTREQUIRED" "STATESWITHRECIPROCITY"
 const putIntoArray = [joined];  // ["VEHICLELISTREQUIRED" "STATESWITHRECIPROCITY"]

Of course you can put the joined string immediately into an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.