gpt4 book ai didi

javascript - 如何在angular js和html5中显示来自javascript对象的特定代码的名称

转载 作者:行者123 更新时间:2023-11-28 01:09:01 25 4
gpt4 key购买 nike

我有一个具有以下数组的 Angular Controller ,该数组具有 3 个值。

controller.medicalInstitues;

我想获取数组中代码为“AUS”的第 4 个对象。然后,我想在父数组中选择的对象中仅显示代码为“SYD”和“MEL”的 2 个医疗机构的名称。

类似下面的内容:

var country = select controller.medicalInstitues.countryCode = "AUS"
var institues = select controller.medicalInstitues.name from country.code="SYD" and "MEL";

now I need to bind these in the UI (Angular).

<span class="code"> {{ controller.institutes.name }}</span>

最佳答案

假设您在 medicalInstitutees 中获得了值列表,那么您可以在 angularjs Controller 中执行

$scope.institues = medicalInstitues.filter(function(value){
return value.countryCode == "AUS" && (value.code == "SYD" || value.code == "MEL");
});

在 HTML 中你可以使用 ng-repeat:

<div controller="controller">
....
<span ng-repeat="institue in institues">{{institue.name}}</span>
....
</div>

关于javascript - 如何在angular js和html5中显示来自javascript对象的特定代码的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38493384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com