标签:angularjs
上代码:
<!DOCTYPE html> <html ng-app="app"> <head> <meta charset="UTF-8"> <title></title> <script src="lib/angular.js"></script> <script> var app = angular.module(‘app‘, []); app.controller(‘selectController‘, function ($scope) { $scope.mycity = ‘上海‘; $scope.Cities = [{ id: 1, name: ‘北京‘, group: ‘中国‘ }, { id: 2, name: ‘上海‘, group: ‘中国‘ }, { id: 3, name: ‘广州‘,group:‘中国‘ }]; }); </script> </head> <body> <div ng-controller="selectController">{{mycity}} <select ng-model="mycity" ng-options="v.name as v.name for v in Cities"> </select> </div> </body> </html>
"v.name as v.name for v in Cities"这段代码最重要,
Cities是数据来源,
v是Cities中的子数据,
第二个v.name将会展示在option中,
第一个v.name将会把值和ng-model="mycity"进行同步。
本文出自 “11416117” 博客,请务必保留此出处http://11426117.blog.51cto.com/11416117/1768685
标签:angularjs
原文地址:http://11426117.blog.51cto.com/11416117/1768685