任何人都可以解释ngoptions [英] can anyone explain ngoptions

查看:77
本文介绍了任何人都可以解释ngoptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以解释这段代码:

鉴于$ scope上的这一系列项目:



$ scope.items = [{

id:1,

label:'aLabel',

subItem:{name:' aSubItem'}

},{

id:2,

label:'bLabel',

subItem: {name:'bSubItem'}

}];



< select ng-options =item as item.label for item in项目按项目跟踪.idng-model =selected>< / select>



在ng-options中我们指定了

item as item.label for item in item by item.id任何人都可以解释这句话

Hi,
can anyone explain this code:
Given this array of items on the $scope:

$scope.items = [{
id: 1,
label: 'aLabel',
subItem: { name: 'aSubItem' }
}, {
id: 2,
label: 'bLabel',
subItem: { name: 'bSubItem' }
}];

<select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>

In ng-options we have specified
"item as item.label for item in items track by item.id" can anyone explain this statement

推荐答案

范围:


scope:


scope.items = [{

id:1,

label:'aLabel',

subItem:{name:'aSubItem'}

},{

id:2,

label:'bLabel' ,

subItem:{name:'b SubItem'}

}];



< select ng-options =item as item.label for item in item by item .idng-model =selected>< / select>



在ng-options中我们指定了

item as item.label for item in item by item.id任何人都可以解释这个陈述
scope.items = [{
id: 1,
label: 'aLabel',
subItem: { name: 'aSubItem' }
}, {
id: 2,
label: 'bLabel',
subItem: { name: 'bSubItem' }
}];

<select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>

In ng-options we have specified
"item as item.label for item in items track by item.id" can anyone explain this statement


我不知道Angular但是我猜它会解析为类似的东西:

I don't know Angular but I would guess it parses out to something like:
Select the item.label from the items array where the selected value matches the item.id


这篇关于任何人都可以解释ngoptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆