简体   繁体   English

我无法基于angularjs中的键值对从json对象获取特定数据

[英]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. 我无法基于angularjs中的键值对从json对象获取特定数据。

    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 : $ scope.name包含:

[{"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. 但我无法从中获取ID。 Help me out do this. 帮帮我。

$scope.name is a list of objects $scope.name是对象列表

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.name重构$scope.name $scope.names因为您可以获得列表,这对您很清楚。

$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 可能对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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