1.基本下拉效果(lable for value in array)

  其中select标签中的ng-model属性必须有,其值为选中的对象或属性值。

  

    <div ng-controller="ngselect">
<p>usage:label for value in array</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:label for value in array(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 for value in array</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的绑定

    下面selected的值为optData的id
  

    <div ng-controller="ngselect4">
<p>usage:select as label for value in array</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: '黃'
}];
}]);

5.ng-options 多级下拉

<div ng-controller="ngselect5">
<select ng-model="selectedPerson" ng-options="obj.name for obj in people"></select>
<select ng-model="selectedGenre">
<option ng-repeat="label in people[selectedPerson.id].interest">{{label}}</option>
</select>
</div>
m1.controller("ngselect5",['$scope',function($sc){
$sc.people = [
{
id: 0,
name: '张三',
interest: [
'爬山',
'游泳',
'旅游',
'美食'
]
},
{
id: 1,
name: '李四',
interest: [
'音乐',
'美食',
'Coffee',
'看书'
]
},
{
id: 2,
name: '王五',
interest: [
'音乐',
'电影',
'中国好声音',
'爸爸去哪了',
'非常静距离'
]
},
{
id: 3,
name: '小白',
interest: [
'游泳',
'游戏',
'宅家里'
]
}
];
}]);

效果:http://runjs.cn/detail/nhi8ubrb

最新文章

  1. guava学习--AsyncFunction
  2. 369. Plus One Linked List
  3. 手把手教你用新浪云容器 Java 搭建自己的网站
  4. 为nginx增加nginx_http_concat模块
  5. CUDA学习笔记(一)——CUDA编程模型
  6. HttpHandler中无法使用Session(context.Session 为Null)
  7. Quartz.NET 2.0 学习笔记(1) :Quartz.NET简介
  8. InnoDB主要数据结构及调用流程
  9. 【正常向】CODEVS上分黄金
  10. POJ 1470 Closest Common Ancestors(最近公共祖先 LCA)
  11. python网络爬虫与信息提取 学习笔记day1
  12. 【转】JY 博客
  13. Arch Linux VMware虚拟机(新手)安装教程
  14. DllImport使用
  15. 快排+java实现
  16. Rest数据服务查询类-根据id查询
  17. linux磁盘检测和修复
  18. 基于canvas+ajax+zui.js的蓄电池监控系统
  19. DSDS,双模,双卡,双待,单待,双通,单通,概念及相互关系?【转】
  20. 1. myeclipse设置jsp默认打开方式为jsp Editor

热门文章

  1. 03006_DOS操作数据乱码解决
  2. 编程算法 - 水洼的数量 代码(C)
  3. 測试CPU支持指令集AVX,AVX2,SSE情况的代码【VS2010调试通过】
  4. jquery 04
  5. widget-移除底部小部件内容
  6. jmeter--FTP测试
  7. django遇到的那些古怪问题
  8. yarn的安装和使用
  9. lighttpd + php for android 安卓上的WEB服务器
  10. cv2.putText 文字换行('\n')无法解析换行