AngularJs: 如何通过不带任何标签的键传递值?

AngularJs: how to get value by passing key without any label?

我是 angular 键值概念的新手。下面是我的 json object-> key,value.

键->字符串 值->对象

{
   "Value 3": {
    "paymentRequestMethod": null,
    "bankHolderName": "BANKHOLDER3",
    "routingNumber": "278723",
    "bankAccountNumber": "BANKACCOUNT1",
    "reEnteredBankAccountNumber": null,
    "accountType": "savings",
    "bankName": "BANK3",
    "accountNumberVerificationValue": null,
    "encryptedBankAccountNumber": null,
    "enrollEftIndicator": false,
    "status": null
  },
  "Value 4": {
    "paymentRequestMethod": null,
    "bankHolderName": "BANKHOLDER4",
    "routingNumber": "278724",
    "bankAccountNumber": "BANKACCOUNT1",
    "reEnteredBankAccountNumber": null,
    "accountType": "savings",
    "bankName": "BANK4",
    "accountNumberVerificationValue": null,
    "encryptedBankAccountNumber": null,
    "enrollEftIndicator": false,
    "status": null
  },
  "Value 1": {
    "paymentRequestMethod": null,
    "bankHolderName": "BANKHOLDER1",
    "routingNumber": "278721",
    "bankAccountNumber": "BANKACCOUNT1",
    "reEnteredBankAccountNumber": null,
    "accountType": "savings",
    "bankName": "BANK1",
    "accountNumberVerificationValue": null,
    "encryptedBankAccountNumber": null,
    "enrollEftIndicator": false,
    "status": null
  },
  "Value 2": {
    "paymentRequestMethod": null,
    "bankHolderName": "BANKHOLDER2",
    "routingNumber": "278722",
    "bankAccountNumber": "BANKACCOUNT1",
    "reEnteredBankAccountNumber": null,
    "accountType": "savings",
    "bankName": "BANK2",
    "accountNumberVerificationValue": null,
    "encryptedBankAccountNumber": null,
    "enrollEftIndicator": false,
    "status": null
  },
  "Value 0": {
    "paymentRequestMethod": null,
    "bankHolderName": "BANKHOLDER0",
    "routingNumber": "278720",
    "bankAccountNumber": "BANKACCOUNT1",
    "reEnteredBankAccountNumber": null,
    "accountType": "savings",
    "bankName": "BANK0",
    "accountNumberVerificationValue": null,
    "encryptedBankAccountNumber": null,
    "enrollEftIndicator": false,
    "status": null
  }
}

我看到很多例子都有键和值的标签,所以我们可以使用 angular.foreach() 进行迭代。我的问题是如何在不使用标签的情况下通过传递密钥来获取价值(如上 json)。这可能吗??

提前致谢。

您也可以使用 javascript 来完成。

试试这个

<script>

  var tempObj = {
    "Value 3": {
     "paymentRequestMethod": null,
     "bankHolderName": "BANKHOLDER3",
     "routingNumber": "278723",
     "bankAccountNumber": "BANKACCOUNT1",
     "reEnteredBankAccountNumber": null,
     "accountType": "savings",
     "bankName": "BANK3",
     "accountNumberVerificationValue": null,
     "encryptedBankAccountNumber": null,
     "enrollEftIndicator": false,
     "status": null
    },
    "Value 4": {
     "paymentRequestMethod": null,
     "bankHolderName": "BANKHOLDER4",
     "routingNumber": "278724",
     "bankAccountNumber": "BANKACCOUNT1",
     "reEnteredBankAccountNumber": null,
     "accountType": "savings",
     "bankName": "BANK4",
     "accountNumberVerificationValue": null,
     "encryptedBankAccountNumber": null,
     "enrollEftIndicator": false,
     "status": null
    },
    "Value 1": {
     "paymentRequestMethod": null,
     "bankHolderName": "BANKHOLDER1",
     "routingNumber": "278721",
     "bankAccountNumber": "BANKACCOUNT1",
     "reEnteredBankAccountNumber": null,
     "accountType": "savings",
     "bankName": "BANK1",
     "accountNumberVerificationValue": null,
     "encryptedBankAccountNumber": null,
     "enrollEftIndicator": false,
     "status": null
    },
    "Value 2": {
     "paymentRequestMethod": null,
     "bankHolderName": "BANKHOLDER2",
     "routingNumber": "278722",
     "bankAccountNumber": "BANKACCOUNT1",
     "reEnteredBankAccountNumber": null,
     "accountType": "savings",
     "bankName": "BANK2",
     "accountNumberVerificationValue": null,
     "encryptedBankAccountNumber": null,
     "enrollEftIndicator": false,
     "status": null
    },
    "Value 0": {
     "paymentRequestMethod": null,
     "bankHolderName": "BANKHOLDER0",
     "routingNumber": "278720",
     "bankAccountNumber": "BANKACCOUNT1",
     "reEnteredBankAccountNumber": null,
     "accountType": "savings",
     "bankName": "BANK0",
     "accountNumberVerificationValue": null,
     "encryptedBankAccountNumber": null,
     "enrollEftIndicator": false,
     "status": null
    }
   }

   console.log(tempObj['Value 0']);
   console.log(tempObj['Value 1']);
   console.log(tempObj['Value 4']);
</script>

试试这个。

<!DOCTYPE html>
<html ng-app="myApp">

<head>
    <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
    <script>
        var myApp = angular.module("myApp", []);
        myApp.controller("AppControler", function ($scope) {

            $scope.Options= ["Value 0", "Value 1", "Value 2", "Value 3", "Value 4"];
            $scope.DataItems = {
                              "Value 3": {
                                "paymentRequestMethod": null,
                                "bankHolderName": "BANKHOLDER3",
                                "routingNumber": "278723",
                                "bankAccountNumber": "BANKACCOUNT1",
                                "reEnteredBankAccountNumber": null,
                                "accountType": "savings",
                                "bankName": "BANK3",
                                "accountNumberVerificationValue": null,
                                "encryptedBankAccountNumber": null,
                                "enrollEftIndicator": false,
                                "status": null
                              },
                              "Value 4": {
                                "paymentRequestMethod": null,
                                "bankHolderName": "BANKHOLDER4",
                                "routingNumber": "278724",
                                "bankAccountNumber": "BANKACCOUNT1",
                                "reEnteredBankAccountNumber": null,
                                "accountType": "savings",
                                "bankName": "BANK4",
                                "accountNumberVerificationValue": null,
                                "encryptedBankAccountNumber": null,
                                "enrollEftIndicator": false,
                                "status": null
                              },
                              "Value 1": {
                                "paymentRequestMethod": null,
                                "bankHolderName": "BANKHOLDER1",
                                "routingNumber": "278721",
                                "bankAccountNumber": "BANKACCOUNT1",
                                "reEnteredBankAccountNumber": null,
                                "accountType": "savings",
                                "bankName": "BANK1",
                                "accountNumberVerificationValue": null,
                                "encryptedBankAccountNumber": null,
                                "enrollEftIndicator": false,
                                "status": null
                              },
                              "Value 2": {
                                "paymentRequestMethod": null,
                                "bankHolderName": "BANKHOLDER2",
                                "routingNumber": "278722",
                                "bankAccountNumber": "BANKACCOUNT1",
                                "reEnteredBankAccountNumber": null,
                                "accountType": "savings",
                                "bankName": "BANK2",
                                "accountNumberVerificationValue": null,
                                "encryptedBankAccountNumber": null,
                                "enrollEftIndicator": false,
                                "status": null
                              },
                              "Value 0": {
                                "paymentRequestMethod": null,
                                "bankHolderName": "BANKHOLDER0",
                                "routingNumber": "278720",
                                "bankAccountNumber": "BANKACCOUNT1",
                                "reEnteredBankAccountNumber": null,
                                "accountType": "savings",
                                "bankName": "BANK0",
                                "accountNumberVerificationValue": null,
                                "encryptedBankAccountNumber": null,
                                "enrollEftIndicator": false,
                                "status": null
                              }
                };
            
            $scope.OnOptionSelect = function(){
                console.log($scope.DataItems[$scope.SelectedOption]);
            }
        });
    </script>
</head>

<body ng-controller="AppControler">
    <select ng-options="option for option in Options" ng-change="OnOptionSelect()" ng-model="SelectedOption"></select>
</body>

</html>