我需要为使用ng-options生成的选项添加一个类。这些选项是从Svc列出的,我还需要插入一个从该对象调用的类。我已经看到其他线程显示如何执行此操作,但它们都引用了对象的布尔值,我只需要将字符串作为类调用。
任何人都可以伸出援助之手。我知道这会很简单。
<select class="report-user" ng-change="testchange(curTest)" ng-model="curTest" ng-options="value.LinkToken as value.Name for value in tests" options-class="{ 'minor-account' : ALLOWED_FOR_MINOR}" required>
这是从Svc调用的对象:
"Employees": [
{
"ExtensionData": {},
"CanChangeNotices": true,
"CanEditData": true,
"CanRefillScripts": true,
"CanRunReports": true,
"CanViewData": true,
"DateOfBirth": "/Date(1448949600000)/",
"EmployeeClass": "ALLOWED_FOR_MINOR",
"EmployeeMessage": "You have been given access to this employee's information.",
"EmployeeStatus": "Allowed For Minor",
"EmployeeTypeId": 3,
"EmployeeTypeName": "Trainee",
"FirstName": "Sqaweb1",
"HasAccount": false,
"IsAuthorized": false,
"LastName": "Test",
"LinkToken": "XxXxXxXxXxXxXxXx"
},
我能够让它将名称插入选项列表并关联linkToken,但我只需要将“EmployeeClass”值设为实际的class =“ALLOWED_FOR_MINOR”(或从服务返回的其他值)即实际上在元素属性上呈现。
这是控制器提供ng-options项目的地方。
$scope.tests = [];
$scope.tests = $scope.user.Employees.map(function(item){
return {
'Name':item.FirstName,
'LinkToken':item.LinkToken
}});
$scope.tests.splice(0, 0, {
'Name': $scope.user.FirstName,
'LinkToken': $scope.user.LinkToken
});
$scope.curTest = $scope.tests[0].LinkToken;