Displaying dynamic JSON array using AngularJS -


hi have angularjs application. connecting server , getting json array data. dynamic data , not sure how content is.

i want display table. how json looks like.

response 1

{   "success": true,   "statusmessage": null,   "responseobject": {     "sourcecontent": {       "classification": [         "new feature",         "bug",         "bug",         "improvement",         "improvement"       ],       "criticalitycode": [         "2",         "1",         "4",         "6",         "9"       ],       "title": [         "title1",         "title2",         "title3",         "title4",         "title5"       ],       "description": [         "description 1",         "description 2",         "description 3",         "description 4",         "description 5"       ],       "priority": [         "major",         "major",         "critical",         "critical",         "major"       ],       "type": [         "type 1",         "type 2",         "type 3",         "type 4",         "type 5"       ],       "date": [         "2014-01-06t11:30:10.000+0000",         "2013-12-30t11:14:27.000+0000",         "2013-12-09t10:21:09.000+0000",         "2013-12-05t08:12:07.000+0000",         "2013-12-05t08:05:46.000+0000"       ]     }   } } 

response 2

{   "success": true,   "statusmessage": null,   "responseobject": {     "sourcecontent": {       "requirements": [         "requirements 1",         "requirements 2",         "requirements 3",         "requirements 4"       ],       "req key": [         "2",         "1",         "6",         "9"       ],       "description": [         "description 1",         "description 2",         "description 3",         "description 4"       ],       "type": [         "type 1",         "type 2",         "type 3",         "type 4"       ],       "date": [         "2013-12-30t11:14:27.000+0000",         "2013-12-09t10:21:09.000+0000",         "2013-12-05t08:12:07.000+0000",         "2013-12-05t08:05:46.000+0000"       ]     }   } } 

js code.

$scope.sourcecontent= $scope.response.responseobject.sourcecontent; 

i don't know how put table contents. html

<table class="table-bordered" style="margin-bottom: 0;">               <tr>                   <th class="border" ng-repeat="(header, value) in sourcecontent">{{header}}</th>               </tr>               <tr>                   <td class="border" >                       {{sourcecontent.classification[0]}}                   </td>               </tr>     </table> 

i able set table column headers. how set contents?

jsfiddle link

i don't know whether control source of response, or might have process response after receive it, from:

{   requirements: [],   description: [] } 

to

[   {requirements: '', description: ''},   {requirements: '', description: ''},   { ... } ] 

at point can use ngrepeat populate table easily.

for sample code convert first second:

var responsearray = []; (var key in response) {   var keyarray = response[key];   (var = 0; < keyarray.length; i++) {       if (responsearray.length - 1 < i) {         var obj = {};         obj[key] = keyarray[i];         responsearray.push(obj);       } else {         var responseelement = responsearray[i];         responseelement[key] = keyarray[i];       }   } } 

i haven't tested above code (wrote in editor ;) ), hope gives idea how implement transition.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -