1

I persist some DB table column values as json string and later on send DB table values as a json object into front end.

[  
   {  
      "jobId":"efe0ace0-8ed9-45ff-9232-974cbdc89b86",
      "jobType":"TestExecutionJob",
      "nextRun":"N/A",
      "lastRun":"2015-11-26 13:26:10.664",
      "createdDate":"2015-11-26 13:26:10.664",
      "executor":"sam",
      "JobDetails":"{\"environment\":\"AA\",\"EmailRecipients\":[\"[email protected]\"],\"extraParams\":{\"FileName\":\"myTest.xml\"}}",
      "status":"active",
      "elapsedTime":"18 minutes ago"
   }
]

I have tried with angularJs ng-repeatbut nothing display.Please let me know how can i accessJobDetails values.(environment,EmailRecipients and FileName)

<ul><li ng-repeat="t in row.entity.JobDetails">{{t.environment}}</li></ul>

Js File

'use strict';
var tepTableModule = angular.module('test',
        [ 'ngAnimate', 'ngTouch','ui.grid','ngResource' ]).factory('Service',
        function($resource) {
            return $resource('/api/jobs', {});
        });

    tepTableModule
    .controller(
            'tepTableCtrl',
            function($scope, Service) {
                $scope.TestData = Service.query();

                var Plantemplate ='<div><ul><li ng-repeat="t in row.entity.JobDetails">{{t.FileName}}</li></ul></div>';

                $scope.tableData = {
                    data : 'TestData',

                    groupsCollapsedByDefault : true,


                    enablePinning : true,
                    columnDefs : [ {
                        field : 'jobId',
                        displayName : 'jobId',
                        visible : false
                    },  {
                        field : 'JobDetails',
                        displayName : 'Plan Name',
                        cellTemplate : Plantemplate,
                        visible : true
                    },
                     {
                        field : 'jobType',
                        displayName : 'JobType',
                        visible : true
                    },
                     {
                        field : 'environment',
                        displayName : 'Environments',
                        visible : true
                    },
                     {
                        field : 'status',
                        displayName : 'Status',
                        visible : true
                    },
                    {
                        field : 'elapsedTime',
                        displayName : 'LastRun',
                        visible : true
                    },
                    {
                        field : 'JobDetails.EmailRecipients',
                        displayName : 'Email Recipients',
                        visible : true
                    },
                    {
                        field : 'executor',
                        displayName : 'Executor',
                        visible : true
                    }
                    ],
                    sortInfo: {
                          fields: ['elapsedTime'],
                          directions: ['desc']
                        },
                    plugins : [ new ngGridAutoRowHeightPlugin() ]
                };

                $scope.changeGroupBy = function(group) {
                    $scope.gridOptions.groupBy(group);
                }
                $scope.clearGroupBy = function() {
                    $scope.gridOptions.$gridScope.configGroups = [];
                    $scope.gridOptions.groupBy();
                }

            });

HTML

<div ng-controller="tepTableCtrl">
    <div  ui-grid="tableData" class="grid"></div>
 </div>

2 Answers 2

3

first parse string to object and then use it

<script>
 var app = angular.module('myApp', []);
    app.controller('myCtrl', ['$scope', function($scope) {

     $scope.json = [  
         {  
            "jobId":"efe0ace0-8ed9-45ff-9232-974cbdc89b86",
            "jobType":"TestExecutionJob",
            "nextRun":"N/A",
            "lastRun":"2015-11-26 13:26:10.664",
            "createdDate":"2015-11-26 13:26:10.664",
            "executor":"sam",
            "JobDetails":"{\"environment\":\"AA\",\"EmailRecipients\":[\"[email protected]\"],\"extraParams\":{\"FileName\":\"myTest.xml\"}}",
            "status":"active",
            "elapsedTime":"18 minutes ago"
         }
      ].map(function(value){
         value.JobDetailParse = JSON.parse(value.JobDetails);
         return value;
      })

    }]);

</script>

Html :

<div ng-repeat = "t in json">
    {{t.JobDetailParse.environment}}
  </div>
Sign up to request clarification or add additional context in comments.

5 Comments

i edited my question please have a look.I fetch data using REST.I am a newbie for angular please let me know how can i achieve this.
see my answer first you convert your string value to object then you can access it.
I tried this way but nothing happen $scope.TestData = Service.query().map(function(value){ value.JobDetailParse = JSON.parse(value.JobDetails); return value; }); <div><ul><li ng-repeat="t in TestData">{{t.JobDetailParse.environment}}</li></ul></div>
can you format your code in your comments by using `` ?
$resource.query() returns a promise. i.e. at the time of binding it is not necessary that data has been fetched.
2

Why not parse the data, IE turn it from string to object?

newObj = JSON.parse(yourString);

Then use ng-repeat on it.

5 Comments

I tried but still the same.I am trying to set data into UI-grid via REST service function($scope, Service) { $scope.TestData = Service.query(); data : 'TestData ',
So now you are trying to send data? Your original question was about mapping within a JSON string. Are you trying to parse test data? IE JSON.parse(TestData) ?
I am fetching data into grid using REST service.I edited my question Please have a look.
Are you sure TestData is even on the scope? Where is test data? Is it in your controller/service?
Since you are returning a promise, maybe a solution would be to JSON.parse(TestData) IN your Service.

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.