<select name="test" ng-model="testVal" ng-options="item.id as item.name for item in items">
当$scope.items = [{id: 1001, name: 'test01'}, {id: 2002, name: 'test02'}]时,当你使用浏览器审核元素时发现item.iid as item.name for item in items和item.name for item in items显示的是一样的,都是
<option value="0" label="test01">test01</option>
<option value="1" label="test02">test02</option>
为什么没有区别呢,测试后发现其实是有区别的,虽然value显示的都是index,但是当你选中一项时,就会发现$scope.testVal就会变为该项的id,这正是我们需要的。(如果使用select2插件,ngModel将会不起作用,而使用jquery获取val或使用select2获取val获取到的都是index值)。
参考网址:http://blog.miniasp.com/post/2013/05/12/AngularJs-ng-module-select-ngOptions-usage-samples.asp