标签:app ted oct mode script scope doc ini http
前景,根据后台返回值选中某个项
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<select ng-init="selectedName = namess" ng-model="selectedName" ng-options="x for x in names">
</select>
</div>
<script>
var app = angular.module(‘myApp‘, []);
app.controller(‘myCtrl‘, function($scope) {
// Runoob 假如后台要我们选中 Runoob
$scope.names = ["Google", "Runoob", "Taobao"];
for(var i = 0; i<$scope.names.length;i++){
if ($scope.names[i] == ‘Taobao‘){
$scope.namess = $scope.names[i] //让其初始化选中这个
}
}
});
</script>
//适合一个下拉列表的情况下,如果有多个遍历循环是思路一样
</body>
</html>
标签:app ted oct mode script scope doc ini http
原文地址:http://www.cnblogs.com/zou1234/p/7777390.html