angularjs - Creating a table header(th) and body(td) from json in angular app -


i have angular app trying create table json. json follows:

[     {         "campus_id": "321",          "name": "0"     },      {         "campus_id": "231",          "name": "1"     },      {         "campus_id": "123",          "name": "2"     } ] 

generally create table in html follows:

<table class="table table-striped">     <tr>         <th>             campus id         </th>         <th>             name         </th>         </tr>     <tr ng-repeat="item in items">         <td >             {{item.campus_id}}         </td>         <td >             {{item.name}}         </td>     </tr> </table> 

how create headers json instead of defining them ourselves?

i add column headers within json result so

columndefs: [      {field: 'campus_id', displayname: 'campus id'},      {field: 'name', displayname: 'name'}],  data: [     {         "campus_id": "57911000",          "name": "0"     },      {         "campus_id": "57911001",          "name": "highland park high school"     },      {         "campus_id": "57911007",          "name": "p s s learning center school"     } ] 

otherwise use key, value pairing ng-repeat="(key,value) in items" filter return 1 row , use {{key}}


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -