ng-option
来源:互联网 发布:空军一号 国际歌 知乎 编辑:程序博客网 时间:2024/06/03 19:01
效果 http://sandbox.runjs.cn/show/nhi8ubrb
.基本下拉效果(lable for value in array)
其中select标签中的ng-model属性必须有,其值为选中的对象或属性值。
<div ng-controller="ngselect">
<p>usage:labelforvalue inarray</p>
<p>选项,{{selected}}</p>
<select ng-model="selected"ng-options="o.id for o in optData">
<option value="">-- 请选择 --</option>
</select>
</div>
m1.controller("ngselect",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory:'男',
ProductName:'水洗T恤',
ProductColor:'白'
},{
id: 10002,
MainCategory:'女',
ProductName:'圓領短袖',
ProductColor:'黃'
},{
id: 10003,
MainCategory:'女',
ProductName:'圓領短袖',
ProductColor:'黃'
}];
}]);
2.自定义下拉显示名称(label for value in array)
label可以根据需要拼接出不同的字符串
<div ng-controller="ngselect2">
<p>usage:labelforvalue inarray(label可以根据需求拼接出不同的字符串)</p>
<p>选项,{{selected}}</p>
<select ng-model="selected"ng-options="(o.ProductColor+'-'+o.ProductName) for o in optData">
<option value="">-- 请选择 --</option>
</select>
</div>
m1.controller("ngselect2",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory:'男',
ProductName:'水洗T恤',
ProductColor:'白'
},{
id: 10002,
MainCategory:'女',
ProductName:'圓領短袖',
ProductColor:'黃'
},{
id: 10003,
MainCategory:'女',
ProductName:'圓領短袖',
ProductColor:'黃'
}];
}]);
3.ng-options 选项分组 group by分组项
<div ng-controller="ngselect3">
<p>usage:label group by groupName forvalue inarray</p>
<p>选项,{{selected}}</p>
<select ng-model="selected"ng-options="(o.ProductColor+'-'+o.ProductName) group by o.MainCategory for o in optData">
<option value="">-- 请选择 --</option>
</select>
</div>
m1.controller("ngselect3",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory:'男',
ProductName:'水洗T恤',
ProductColor:'白'
},{
id: 10002,
MainCategory:'女',
ProductName:'圓領长袖',
ProductColor:'黃'
},{
id: 10003,
MainCategory:'女',
ProductName:'圓領短袖',
ProductColor:'黃'
}];
}]);
4.ng-options 自定义ngModel的绑定
<div ng-controller="ngselect4">
<p>usage:select as label forvalue inarray</p>
<p>选项,{{selected}}</p>
<select ng-model="selected"ng-options="o.id as o.ProductName for o in optData">
<option value="">-- 请选择 --</option>
</select>
</div>
m1.controller("ngselect4",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory:'男',
ProductName:'水洗T恤',
ProductColor:'白'
},{
id: 10002,
MainCategory:'女',
ProductName:'圓領长袖',
ProductColor:'黃'
},{
id: 10003,
MainCategory:'女',
ProductName:'圓領短袖',
ProductColor:'黃'
}];
}]);
阅读全文
0 0
- ng-option
- ng-option的解析
- angularjs中的ng-option
- angularjs ng-model-option
- ng-option 的两种写法
- select option ng-repeat多空白项
- ng-options怎么设置option的value
- angular使用ng-option。默认选中列表第一项
- JS对象比较函数,引发angular的ng-option异常
- ie ng-repeat生成的option 表达式没有解析出来
- Option
- Option
- AngularJS: 使用ng-option生成下拉框并在controller调用
- AngularJS: 使用ng-option生成下拉框并在controller调用
- AngularJS: 使用ng-option生成下拉框,添加全部选择项
- angular使用ng-options,第一个option为空的问题
- NG
- ng
- 图结构练习——最短路径
- HDU-4185-Oil Skimming [二分匹配]
- linux定时任务的设置 crontab 配置指南
- MyBatis Mapper 接口如何通过JDK动态代理来包装SqlSession 源码分析
- 判断网络
- ng-option
- web service 对外发布一个hello world接口(入门)
- LCS,LCIS,LIS模板
- redis乐观锁实现秒杀
- DrawLayout
- 技术的正宗与野路子
- IT行业offer分析
- 双倍回文
- C++ const总结