0

I have a JSON array of objects, which I want to dispaly all of it into a table, but somewhere I'm messing up with something.

Problem Statement: Display JSON array of nested objects in a table including all of its contents.

JSON Data:

{
"loadStops": [{
    "id": 1,
    "sequence": 1,
    "type": "P",
    "stop": {
        "companyId": 148,
        "companyCode": "FWS",
        "legalName": "Frontier WHSE",
        "locations": [{
            "id": 149,
            "city": "PortLavaca",
            "state": "TX",
            "contacts": [{
                "id": 150,
                "medium": "MA",
                "serviceLocator": "000-000-0000",
                "prefered": false,
                "action": 0
            }],
            "action": 0
        }],
        "action": 0
    },
    "apptType": "WDO",
    "appointmentNo": null,
    "commodities": [{
        "id": 0,
        "commodity": "Food",
        "action": 0
    }],
    "action": 0
}, {
    "id": 1,
    "sequence": 1,
    "type": "P",
    "stop": {
        "companyId": 148,
        "companyCode": "FWS",
        "legalName": "Frontier WHSE",
        "locations": [{
            "id": 149,
            "city": "PortLavaca",
            "state": "TX",
            "contacts": [{
                "id": 150,
                "medium": "MA",
                "serviceLocator": "000-000-0000",
                "prefered": false,
                "action": 0
            }],
            "action": 0
        }],
        "action": 0
    },
    "apptType": "WDO",
    "appointmentNo": null,
    "commodities": [{
        "id": 0,
        "commodity": "Food",
        "action": 0
    }],
    "action": 0

}]

}

Please guide me how do I write the code for bootstrap table to achieve all the contents inside the table.

TABLE:

<table class="table table-striped table-hover table-sm">
            <tr>
                <th>headers</th>
            </tr>

            <tr>
                <td> data </td>
                <td>
                    <table>
                        <tr>
                            <td> nested data etc.. </td>
                        </tr>
                    </table>
                </td>
            </tr>


        </table>

Please enlighten my misunderstanding, I'll be thankful to you. Thanks

7
  • 1
    What have you tried? Are you aware of ng-repeat? Commented Feb 23, 2018 at 8:50
  • Do want to show entire JSON as it is into a table? What do you mean by "all of it"? Commented Feb 23, 2018 at 8:50
  • @Mawg yes I know about ng-repeat, but it shows one data cell multiple times... Commented Feb 23, 2018 at 8:51
  • @AnandG Yes I want all of the information, we may exclude actions and ids. Commented Feb 23, 2018 at 8:51
  • 1
    ngFor if for Angular, not AngularJS. Angular is another, different framework. You ned ng-repeat, and you need to nest ng-repeat inside ng-repeat, just like you would nest for loops in any programming language to loop through an array contained in another array. Show what you tried. We won't do your homework. Commented Feb 23, 2018 at 8:59

1 Answer 1

1
      I am just giivng a sample to iterate over nested data:
      $scope.value= yourJson;
      $spope.displayVal= $scope.value.loadStops;
      <table class="table table-striped table-hover table-sm">
            <tr ng-repeat="data in displayVal">
                <th>{{data.id}}</th>
                <!-- show data what you want-->
            </tr>

            <tr ng-repeat="data in displayVal">
                <td> data </td>
                <td>
                    <table>
                        <tr ng-repeat="newData in data.stop.location">
                            <td> nested data etc.. </td>
                        </tr>
                    </table>
                </td>
            </tr>


        </table>
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.