簡體   English   中英

我無法基於angularjs中的鍵值對從json對象獲取特定數據

[英]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);


                });
        }
    })

$ 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"}]

但我無法從中獲取ID。 幫幫我。

$scope.name是對象列表

提取方式為:

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

還值得將$scope.name重構$scope.name $scope.names因為您可以獲得列表,這對您很清楚。

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

您可以像這樣獲得id值var id = $ scope.name [0] .id

嘗試這個

 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> 

可能對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM