angular.js - angular 的ng-option的一些参数option.id as option.title 这里面的as是

浏览:37日期:2023-01-11

问题描述

如下这段代码,as是什么意思?

ng-options='option.id as option.title for option in curOptionArray'

问题解答

回答1:

option.id表示选择的,option.title表示显示的,as就是这个作用

回答2:

可以理解成一个ng的语法 option.id是select提交的值 option.title是select显示的值 option代表数组curOptionArray里面的当前元素

回答3:

可参考官网:https://docs.angularjs.org/api/ng/directive/ngOptions#!

其中有一个例子:

$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>回答4:

可以看看这里Hacking with Angular: 玩转ngOptions指令

相关文章: