我在为 ui-select2 以角度预选一组变量时遇到问题。
我的控制器:
$scope.roles= [{"_id":"545e8f2f64f29dc1540f5a88","__v":0,"created":"2014-11-08T21:46:23.553Z","comments":"Administrator Rolle","name":"admin"}];
$scope.userdata.roles = [{"_id":"545e8f2f64f29dc1540f5a88","__v":0,"created":"2014-11-08T21:46:23.553Z","comments":"Administrator Rolle","name":"admin"}];
我的观点:
<ui-select multiple ng-model="userdata.roles" theme="select2" ng-disabled="disabled" class="input-medium" style="width:100% !important;">
<ui-select-match placeholder="Wählen Sie ein oder mehrere Rollen...">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="role in roles | filter:$select.search">
{{role.name}} ({{role.comments}})
</ui-select-choices>
</ui-select>
ng-model 不预先选择值
当我分配$scope.userdata.roles = $scope.roles
它会工作。
如果有可能我想使用这个数组,但我无法用这个进行编码:
$scope.roles= [{"_id":"545e8f2f64f29dc1540f5a88","__v":0,"created":"2014-11-08T21:46:23.553Z","comments":"Administrator Rolle","name":"admin"}];
$scope.userdata.roles = ["admin"];
编辑:当我用它作为我的观点时:
<ui-select multiple ng-model="userdata.roles" theme="select2" ng-disabled="disabled" style="width:100% !important;">
<ui-select-match placeholder="Bitte wählen Sie eine oder mehrere Rollen...">{{$item.name}} <{{$item.comments}}></ui-select-match>
<ui-select-choices repeat="role.name as role in roles">
<div ng-bind-html="role.name | highlight: $select.search"></div>
<small>
{{role.comments}}
</small>
</ui-select-choices>
</ui-select>
这对于我的控制器:
$scope.roles = [
{
"_id" : "545e8f2f64f29dc1540f5a88",
"__v" : 0,
"created" : "2014-11-08T21:46:23.553Z",
"comments" : "Administrator Rolle",
"name" : "admin"
}
];
$scope.userdata.roles = ["admin"];
它也行不通。时间有问题吗?