Javascript AngularJS+MEANJS-将对象模型属性用作筛选器的数组键
我有一个MEANJS应用程序,带有国家/地区的CRUD模块。当我从默认列表视图中单击某个国家时,它会将我带到视图-country.client.view。我已经为currencycode在模型中添加了一个字段。当我单击国家时,它会将我带到一个页面,我希望它通过将国家模型的currencycode字段与我从json导入的数据相匹配,从json中调出汇率Javascript AngularJS+MEANJS-将对象模型属性用作筛选器的数组键,javascript,json,angularjs,meanjs,Javascript,Json,Angularjs,Meanjs,我有一个MEANJS应用程序,带有国家/地区的CRUD模块。当我从默认列表视图中单击某个国家时,它会将我带到视图-country.client.view。我已经为currencycode在模型中添加了一个字段。当我单击国家时,它会将我带到一个页面,我希望它通过将国家模型的currencycode字段与我从json导入的数据相匹配,从json中调出汇率 //view-country.client.view <section data-ng-controller="CountriesCont
//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”中包含countrycode,它将返回正确的速率。{{country.currencycode}从我的MongoDB中带回AFN,但是如果我尝试将{{country.currencycode}嵌入到'AFN'所在的位置,它将无法工作。我试过检查过滤器,但无法使其正常工作。基本上,每当我单击一个国家时,我都希望它通过使用model属性作为字符串来显示该国家的汇率,以便从数组中获取正确的对象。我已经在论坛上呆了一整天了,无法理解这一点。提前谢谢。如果我理解正确,您不想在这里硬编码“AFG”吗
{{exchangeRates.rates['AFN']}}
如果是这样的话,你试过这个吗
{{exchangeRates.rates[country.currencycode]}}
如果我理解正确,您不希望在这里硬编码'AFG:{{{exchangeRates.rates['AFN']}}?如果是这样的话,你试过{{exchangeRates.rates[country.currencycode]}}吗?哇,我试过['country.currencycode',但在尝试了这么多其他组合后,从未尝试过,真是令人尴尬的疏忽。你是对的,它按照你的建议工作。张贴作为一个答案,我会接受!非常感谢。