1.基本下拉效果(lable for value in array)
其中select标签中的ng-model属性必须有,其值为选中的对象或属性值。
m1.controller("ngselect",['$scope',function($sc){ $sc.selected = ''; $sc.optData = [{ id: 10001, MainCategory: '男', ProductName: '水洗T恤', ProductColor: '白' },{ id: 10002, MainCategory: '女', ProductName: '�A�I短袖', ProductColor: '�S' },{ id: 10003, MainCategory: '女', ProductName: '�A�I短袖', ProductColor: '�S' }]; }]);usage:label for value in array
选项,{{selected}}
2.自定义下拉显示名称(label for value in array)
label可以根据需要拼接出不同的字符串
m1.controller("ngselect2",['$scope',function($sc){ $sc.selected = ''; $sc.optData = [{ id: 10001, MainCategory: '男', ProductName: '水洗T恤', ProductColor: '白' },{ id: 10002, MainCategory: '女', ProductName: '�A�I短袖', ProductColor: '�S' },{ id: 10003, MainCategory: '女', ProductName: '�A�I短袖', ProductColor: '�S' }]; }]);usage:label for value in array(label可以根据需求拼接出不同的字符串)
选项,{{selected}}
3.ng-options 选项分组
group by分组项
m1.controller("ngselect3",['$scope',function($sc){ $sc.selected = ''; $sc.optData = [{ id: 10001, MainCategory: '男', ProductName: '水洗T恤', ProductColor: '白' },{ id: 10002, MainCategory: '女', ProductName: '�A�I长袖', ProductColor: '�S' },{ id: 10003, MainCategory: '女', ProductName: '�A�I短袖', ProductColor: '�S' }]; }]);usage:label group by groupName for value in array
选项,{{selected}}
4.ng-options 自定义ngModel的绑定
下面selected的值为optData的id 效果 http://sandbox.runjs.cn/show/nhi8ubrb
m1.controller("ngselect4",['$scope',function($sc){ $sc.selected = ''; $sc.optData = [{ id: 10001, MainCategory: '男', ProductName: '水洗T恤', ProductColor: '白' },{ id: 10002, MainCategory: '女', ProductName: '�A�I长袖', ProductColor: '�S' },{ id: 10003, MainCategory: '女', ProductName: '�A�I短袖', ProductColor: '�S' }]; }]);usage:select as label for value in array
选项,{{selected}}
效果:http://runjs.cn/detail/nhi8ubrb
以上所述就是本文的全部内容了,希望大家能够喜欢。