我正在尝试使用'track by'表达式按值跟踪我的选择,但是,我无法让它工作。
JS
var app = angular.module('cwsystem', []).controller('RegistrationCtrl', ['$scope', function($scope){
$scope.roles = [
{value: '110', position: 'Security Chief'},
{value: '111', position: 'Security Officer'}
];
}]);
HTML
<select name="userStatus" ng-model="user.userStatus" ng-options=" role.value as role.position for role in roles track by role.position" class="form-control input-sm" required>
<option value="">--Select Status--</option>
</select>
我希望浏览器呈现如下结果:
<select name="userStatus" ng-model="user.userStatus" ng-options=" role.value as role.position for role in roles track by role.position" class="form-control input-sm" required>
<option value="">--Select Status--</option>
<option value="110">Security Chief</option>
<option value="111">Security Officer</option>
</select>
请问这个问题可以得到一些帮助吗?
答案 0 :(得分:3)
ng-options不接受&#34; role.value为role.position,角色角色跟踪角色。位置&#34;表达
<select name="userStatus" ng-model="user.userStatus" ng-options=" role.value as role.position for role in roles" class="form-control input-sm" required>
<option value="">--Select Status--</option>
</select>
如果在ng-option中使用上面的表达式,您将在ng-model变量中获得选定的值