AngularJS使用ng-repeat指令实现下拉框
AngularJs 的 ng-repeat 让我们非常方便的遍历数组生成 Dom 元素,但是使用不当也会有性能问题。下面给大家分享在项目中使用ng-repeat指令实现下拉框。
1、问题背景
select下拉框里option组装成下拉框,这里利用ng-repeat指令来创建
2、实现源码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS之下拉框(方式二)</title> <script type="text/javascript" src="../js/angular.min.js" ></script> <script> var app = angular.module("secondApp",[]); app.controller("secondCon",function($scope){ $scope.trees = ["松树","樟树","枫树","枣树","桃树"]; }); </script> </head> <body> <div ng-app="secondApp" ng-controller="secondCon"> <select style="width: 200px;"> <option ng-repeat="tree in trees">{{tree}}</option> </select> </div> </body> </html>
3、问题说明
ng-repeat指令可以重复数据
相关推荐
鸟菜小端前 2018-09-12
CrazyDogWang 2017-02-14
zbwroom 2016-09-23
youyouzouzou 2015-11-30
princejingyun 2013-01-30
Oranq 2013-09-24
闲听风月 2018-01-16
forthemyth 2017-09-18
codergirl 2017-07-06
Inuyasha 2017-01-21
forthemyth 2017-01-21
鸟菜小端前 2017-01-19
thesameguo 2016-12-31
itseebin 2019-04-29
DataCastle 2016-12-13
鸟菜小端前 2016-11-02
codergirl 2019-04-29
鸟菜小端前 2019-04-26
雅特岚蒂斯 2019-04-25