<select id="e1" style="width:100%" ui-select2 tabindex="-1" ng-init="GetAllAgent()" ng-model="Agent" ng-options="ctr as ctr.AgentName for ctr in ListAgent track by ctr.AgentId" ng-change="GetSubAgentList(Agent.AgentId)">
<option value=""> </option></select>当它处于编辑模式时,无法使用以下代码设置默认值
angular.forEach($scope.ListAgent, function (value, index) {
if (value.AgentId == HR.AgentId) {
$scope.Agent = $scope.ListAgent[index];
}
})
$scope.ListAgent= [{ AgentId: "0", AgentName:"Ann" }, { AgentId: "1", AgentName:"Muh" }];和
HR.AgentId=1发布于 2017-09-30 08:36:49
首先,ui-select2不支持ng-options:https://github.com/angular-ui/ui-select2/issues/252
此外,ui-select2不适用于ng-repeat:https://github.com/angular-ui/ui-select2/issues/162
解决方案是使用input
<input ui-select2="select2Options" ng-model="Agent"/>其中select2Options是:
$scope.select2Options = {
data:$scope.ListAgent
}列表应该有结构:[{id,text}],所以$scope.ListAgent将是
$scope.ListAgent= [{ id:0, text:"Ann" }, { id:1, text:"Muh" }];演示柱塞
对于位置持有者,添加data-placeholder="----"
https://stackoverflow.com/questions/46499828
复制相似问题