如何在angular js和html5中显示javascript对象中特定代码的名称
how to display name of a particular code from a javascript object in angular js and html5
我有一个角度控制器,它有以下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";
});
相关文章:
- 面向对象的Javascript代码在IE7中不起作用
- JavaScript代码问题:我正在将对象转换为数组
- Angular:使用选择列表选择过滤代码中的对象
- 创建对象函数原型和代码是错误的
- 将代码转换为可重用对象
- 代码挑战:创建一个跟踪对象实例总数的类Foo
- 分析云代码访问对象
- 为什么代码会指向window对象
- 为什么Javascript程序员更喜欢在代码中重复字符串作为常量,而不是使用枚举类型的对象
- AngularJS错误:请求的键的值不是对象.keys@[本地代码]
- 如何让我的正则表达式代码在我的dojo cellWidget对象上工作
- 解析服务器云代码保存对象
- 如何从给定的代码中获取JSON对象
- XMLHttpRequest 对象状态代码为 0
- Ace代码编辑器:缓存模式对象
- <对象> 代码在 Chrome 中更改其数据属性时不会刷新
- 了解Javascript对象代码段
- 将jQuery对象/代码转换为插件
- 对非对象代码点火器上的成员函数的调用
- 为什么我得到错误的输出,当我修改以下Javascript对象代码