我想知道AngularJS ng-options-下拉列表中的名称可以使用2个不同的变量吗?
以这个简化的示例为例-我希望下拉列表中包含国家/地区-城市。我知道这很简单,但这可能与在select下拉列表之外组合变量有关吗?
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="HelloController" >
<select ng-model="blah" ng-options="city.Id as city.CityName for city in cities"></select>
</div>
<script>
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.cities = [
{Id: '000001', Country:'USA', CityName: 'Chicago'},
{Id: '000002', Country:'Ireland', CityName: 'Dublin'},
{Id: '000003', Country:'Spain', CityName: 'Barcelona'},
{Id: '000004', Country:'USA', CityName: 'Boston'},
];
} );
</script>
</body>
</html>
您应该能够像这样完成此操作:
ng-options="city.Id as (city.Country + ' - ' + city.CityName) for city in cities"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句