我有2个链接的JSON对象数组。
范例:
国家/地区:

[{
      "countryCode":"IN",
      "countryName":"India",
      "currencyCode":"INR"
   },
{
      "countryCode":"US",
      "countryName":"United States",
      "currencyCode":"USD"
   }]


货币:

 [{
      "code":"INR",
      "name":"Indian Rupee",
      "locale":"kok_IN",
      "display":1
   }, {
      "code":"USD",
      "name":"US Dollar",
      "locale":"en_US_POSIX",
      "display":1
   }]


上面的两个json对象与代码链接。
我正在尝试通过链接currencycode显示货币对象中的Currencyname。
我像波纹管一样显示:

<tr ng-repeat="country in countries | filter : query | orderBy : 'name'">
<td>{{ country.countryName }}</td>
<td>{{ }}</td> <!-- Currency name here -->
</tr>


如何在此处显示货币名称?

最佳答案

使用功能getCurrencyByCountry为我工作:



angular.module("App", []).controller("AppController", function($scope) {
    $scope.countries = [{
        "countryCode": "IN",
        "countryName": "India",
        "currencyCode": "INR"
    }, {
        "countryCode": "US",
        "countryName": "United States",
        "currencyCode": "USD"
    }];

    $scope.currency = [{
        "code": "INR",
        "name": "Indian Rupee",
        "locale": "kok_IN",
        "display": 1
    }, {
        "code": "USD",
        "name": "US Dollar",
        "locale": "en_US_POSIX",
        "display": 1
    }];

    $scope.getCurrencyByCountry = function(country){
        var currency = "";
        angular.forEach($scope.currency, function(value, key) {
            if(country.currencyCode == value.code){
                currency = value.name;
                return false;
            }
        });
        return currency;
    }
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table ng-app="App" ng-controller="AppController">
  <tr ng-repeat="country in countries |orderBy : 'name'">
    <td>{{country.countryName}}</td>
    <td>{{getCurrencyByCountry(country)}}</td>
    <!-- Currency name here -->
  </tr>
<table>

09-12 00:29
查看更多