AngularJS + MEANJS - 使用对象模型 属性 作为过滤器的数组键

AngularJS + MEANJS - Use object model property as array key for filter

我有一个带有国家 CRUD 模块的 MEANJS 应用程序。当我从默认列表视图中单击一个国家/地区时,它会将我带到视图-country.client.view。我在我的货币代码模型中添加了一个字段。当我单击该国家/地区时,它会将我带到一个页面,我希望它通过将国家/地区模型的货币代码字段与我从 json 导入的数据相匹配,从 json 中调出汇率。

//view-country.client.view

<section data-ng-controller="CountriesController" data-ng-init="findRate()">
 <div class="col-lg-3 col-md-6 col-sm-12">
    <div class="panel panel-dark">
        <div class="panel-heading">Currency</div>
        <div class="panel-body">
        {{country.currencycode}}
            <p>The exchange rate is {{exchangeRates.rates['AFN']}}
            </div>
         </div>
   </div>
</section>





//findRate() for data-ng-init in CountriesController

$scope.findRate = function() {

            $scope.country = Countries.get({ 
                    countryId: $stateParams.countryId
                });

            $http.get('http://localhost:3000/rates.json').
            success(function(data) {
                $scope.exchangeRates = data        
            });
        };

一切都与 JSON 导入一起工作,如果我包括国家代码(在这个例子中 'AFN' 代表阿富汗),它将 return 正确率。 {{country.currencycode}} 从我的 MongoDB 带回 AFN,但如果我尝试将 {{country.currencycode}} 嵌入到 'AFN' 所在的位置,它将不起作用。我试过查看过滤器,但无法使它们正常工作。基本上,每当我单击一个国家时,我希望它通过使用模型 属性 作为从我的数组中获取正确对象的字符串来仅显示该国家/地区的汇率。我整天都在论坛上,无法弄清楚这一点。提前谢谢你。

如果我理解正确的话,你不希望 'AFG' 在这里被硬编码?

{{exchangeRates.rates['AFN']}}

如果是这样,你试过了吗?

{{exchangeRates.rates[country.currencycode]}}