AngularJS select下拉框的使用

http://www.cnblogs.com/wolf-sun/p/4614532.html
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Select Demo</title>
		<script type="text/javascript" src="js/angular.min.js" ></script>
	</head>
	
	<body ng-app="myApp" ng-controller="myCtrl">
		<!-- ng-options -->
		<!-- 数据源为数组 -->
		<select name="" ng-model="selectedCar" ng-options="car for car in Cars">
		</select>
		
		<!-- 数据源为对象数组 -->
		<select name="" ng-model="selectedSite" ng-options="site.site as site.site for site in Sites ">
		</select>
		
		<!-- 数据源为对象 -->
		<select name="" ng-model="selectedsite" ng-options="x for (x, y) in sites ">
		</select>
		
		<!-- 数据源为对象且数据源的属性值也为对象 -->
		<select name="" ng-model="selectedcar" ng-options="y.brand as y.brand for (x, y) in cars ">
		</select>
		
		<!-- 用对象的键-值作为选中的标签组 -->
		<select name="" ng-model="mycity" ng-options="city.name as city.name group by city.group for city in Cities ">
		</select>
		
		<br />
		<br />
		
		<!-- ng-repeat -->
		<!-- 数据源为数组 -->
		<select ng-model="selectedCar">
			<option ng-repeat="car in Cars">{{car}}</option>
		</select>
		<!-- 数据源为对象数组 -->
		<select ng-model="selectedSite">
			<option ng-repeat="site in Sites">{{site.site}}</option>
		</select>
		
		<script>
			var app = angular.module("myApp", [])
			.controller('myCtrl', function($scope) {
				//数组
				$scope.Cars = ['奔驰', '宝马', '三菱'];
				$scope.selectedCar = $scope.Cars[0];
				
				//对象数组
				$scope.Sites = [
				    {site : "Google", url : "http://www.google.com"},
				    {site : "Runoob", url : "http://www.runoob.com"},
				    {site : "Taobao", url : "http://www.taobao.com"}
				];
				$scope.selectedSite = $scope.Sites[0].site;
				
				//对象
				$scope.sites = {
				    site01 : "Google",
				    site02 : "Runoob",
				    site03 : "Taobao"
				};
				$scope.selectedsite = $scope.sites.site01;
				
				//数据源为对象且数据源的属性值也为对象
				$scope.cars = {
			        car01 : {brand : "Ford", model : "Mustang", color : "red"},
			        car02 : {brand : "Fiat", model : "500", color : "white"},
			        car03 : {brand : "Volvo", model : "XC90", color : "black"}
			    };
			    $scope.selectedcar = $scope.cars.car01.brand;
			    
			    $scope.mycity = '北京';
            	$scope.Cities = [
	            	{ id: 1, name: '北京', group: '中国' },
	            	{ id: 2, name: '上海', group: '中国' },
	            	{ id: 3, name: '广州', group: '中国' },
	            	{ id: 4, name: '纽约', group: '美国' }
            	];
			});
			
		</script>
		
	</body>
</html>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值