简体   繁体   中英

I am not able to fetch the particular data from json object based on key value pair in the angularjs

I am not able to fetch the particular data from json object based on key value pair in the angularjs.

    var app = angular.module("myApp", []);
    app.controller("myDialogController", function($http, $scope) {
        alert("nishant is here");

        $scope.onSubmit = function() {
            alert("inside submit function");
        }

        $scope.displayData = function() {
            alert("nishant is here on load");
        }
    });

    app.controller("myCntrl", function($scope, $http) {
        alert("velson is here");
        $scope.displayData = function() {
            alert("inside the velson");
            $http.get("retrieve_1.jsp")
                .then(function(response) {
                    $scope.name = response.data;
                    //$scope.value = $scope.name.id;
                    //alert($scope.value);


                });
        }
    })

Here $scope.name contains :

[{"id":"1","emp_id":"2010","sales_force_id":"sales_force_id_test_url","type_of_request":"New","rfp_rfi":"1","closure_deadline":"2017-09-18 15:23:37.0","mode_of_submission":"S","submission_date":"2017-09-18 15:23:37.0","clarification_date":"2017-09-18 15:23:37.0","extention_date":"2017-09-18 15:23:37.0","region":"Region 1","item_status":"Pending","participants_status":"Pending","reviewer_status":"Pending","description":"null","bid_owner":"null"}]

But i am not able to fetch id from this. Help me out do this.

$scope.name is a list of objects

Fetch is as:

$scope.value = $scope.name[0].id;

Also worth to refactor $scope.name to $scope.names since you get list and it will be clear for you.

$scope.names = response.data;
$scope.value = $scope.names[0].id;

您可以像这样获得id值var id = $ scope.name [0] .id

Try this

 var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.data = [{"id":"1","emp_id":"2010","sales_force_id":"sales_force_id_test_url","type_of_request":"New","rfp_rfi":"1","closure_deadline":"2017-09-18 15:23:37.0","mode_of_submission":"S","submission_date":"2017-09-18 15:23:37.0","clarification_date":"2017-09-18 15:23:37.0","extention_date":"2017-09-18 15:23:37.0","region":"Region 1","item_status":"Pending","participants_status":"Pending","reviewer_status":"Pending","description":"null","bid_owner":"null"}]; } 
 table, th, td { border: 1px solid black; border-collapse: collapse; } 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div ng-app="myApp" ng-controller="MyCtrl"> <table borderd> <tr> <th>Id</th> <th>Emp Id</th> <th>Sales Force Id</th> <th>Item Status</th> </tr> <tr ng-repeat="i in data"> <td>{{i.id}}</td> <td>{{i.emp_id}}</td> <td>{{i.sales_force_id}}</td> <td>{{i.item_status}}</td> </tr> </table> </div> 

May this helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM