Angularjs select总结

本文详细介绍了如何在HTML5中通过AngularJS定义列表和选择项,包括不同方法的使用和展示。

定义列表和选中项

$scope.Current = "Writing code"//定义选中项
$scope.TotalItems =[//定义列表
      { id: 1, type: "Work", name: "Writing code" },
      { id: 2, type: "Work", name: "Testing code" },
      { id: 3, type: "Work", name: "Fixing bugs" },
      { id: 4, type: "Play", name: "Dancing" }
   ];

使用方法:

方法1:
<select class="form-control" ng-model="Current">//只使用其中一列,循环列表
    <option value="">-- 请选择 --</option> <option ng-repeat="item in TotalItems ">{{item.name}}</option>
</select>

 

方法2://拼接字符项
<select class="form-control" ng-model="Current" ng-options="( item.name + '_' + item.id ) for itemin TotalItems">
    <option value="">-- 请选择 --</option>
</select>

 

方法3://与方法1基本相同
<select class="form-control" ng-model="Current" ng-options="item.name for item in TotalItems">
    <option value="">-- 请选择 --</option>
</select>

 

方法4://key为id,显示为name,key只能为数字
<select class="form-control" ng-model="Current" ng-options="item.id as item.name for item in TotalItems">
    <option value="">-- 请选择 --</option>
</select>

 

方法5://实现分组查询
<select class="form-control" ng-model="Current" ng-options="item.id as item.name group by item.type for item in TotalItems">
    <option value="">-- 请选择 --</option>
</select>

 

转载于:https://www.cnblogs.com/sssleon/p/5151856.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值