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

how to display name of a particular code from a javascript object in angular js and html5

本文关键字:对象 代码 javascript 显示 angular js html5      更新时间:2023-09-26

我有一个角度控制器,它有以下3个值的数组。

controller.medicalInstitues;

我想获取数组中代码为"AUS"的第四个对象。然后,我想在从父数组中选择的对象中只显示2个代码为"SYD"answers"MEL"的医疗机构的名称。

如下所示:

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>

假设你在medicalInstitues中得到了你的值列表,那么在angularjs控制器中你可以进行

$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>

在控制器中,要绑定数组中的第四个对象,可以设置:

$scope.AUS=yourArray[3]

然后在html中可以显示对象属性:

{{AUS."object path to name"}}

好吧,如果我很好地理解了你的问题,你可以做以下事情:

// If you have an array that you already know that will come 4 items with the same country code, you can simply do:
$scope.medicalInstitues = array[3];
// Otherwise:
$scope.medicalInstitues = array.filter(function (value) {
  return value.countryCode == "AUS";
})[3];
// To get all 'institues' with the countryCode equals to 'SYD' or 'MEL':
$scope.institues = array.filter(function (value) {
  return value.countryCode == "SYD" || value.countryCode == "MEL";
});