gpt4 book ai didi

javascript - 使用angularjs恢复默认下拉值

转载 作者:行者123 更新时间:2023-11-29 10:10:35 25 4
gpt4 key购买 nike

虽然我已经让这个工作了,但它的工作方式似乎不合适。我有一个显示团队列表的下拉列表 (DDL)。顶部和默认条目是“选择团队...”。尽管我的 DDL 与模型相关联,但“选择团队...”不应该是其中的一部分,因为“选择团队...”对域模型没有任何意义。

当用户点击“添加新”时,表单将被清除,所有 DDL 应恢复为默认值。

这里是相关的 Controller 函数:

scope.addUser = function() {
resetToNewUser();
$scope.profileVisible = true;
$scope.oneAtATime = true;
$scope.accordionStatus = { isFirstOpen: true, isFirstDisabled: false };
}

function resetToNewUser() {
$scope.selectedUser.NtId = "";
$scope.selectedUser.UserId = -1;
$scope.selectedUser.IsActive = true;
$scope.selectedUser.FirstName = "";
$scope.selectedUser.LastName = "";
$scope.selectedUser.JobTitle = "";
$scope.selectedUser.Email = "";
$scope.selectedUser.SecondaryEmail = "";
$scope.selectedUser.PhoneNumber = "";
for(var i = 0; i < $scope.roleList.length; i++) {
if($scope.roleList[i].RoleSystemName.trim() === "BLU") {
$scope.selectedUser.Role = $scope.roleList[i];
}
}
$scope.selectedUser.SupervisorId = null;
//HACK BELOW//
document.getElementById('selTeam').selectedIndex = 0; // <-- This works, but feels like a hack.
$scope.selectedUser.IsRep = false;
for(var i = 0; i < $scope.signingAuthorityList.length; i++) {
if($scope.signingAuthorityList[i].SigningAuthoritySystemName === "SME") {
$scope.selectedUser.SigningAuthority = $scope.signingAuthorityList[i];
}
}
$scope.selectedUser.IsOutOfOfficeEnabled = false;
$scope.selectedUser.OutOfOfficeStartDate = null;
$scope.selectedUser.OutOfOfficeEndDate = null;
$scope.selectedUser.OutOfOfficeAppointedRepId = null;
}

DDL 在模板中的定义方式如下:

<div class="form-group">
<label for="" class="control-label col-sm-2 required">Team</label>
<div class="col-sm-10">
<select class="form-control" id="selTeam"
ng-model="selectedUser.Team"
ng-options="team as team.TeamName for team in teamList track by team.TeamId">
<option value="">Select Team...</option>
</select>
</div>
</div>

有更好的方法吗?

最佳答案

您总是可以删除用户选择占位符选项的功能,对吗?像这样:

<option value="" disabled selected hidden>Select Team...</option>

关于javascript - 使用angularjs恢复默认下拉值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34296975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com