我发布了我的代码。我想从我的选项中删除Kanhu
。
参见工作示例。
var myApp = angular.module('myApp',[]);
function myCtrl ($scope) {
$scope.userProfiles = [
{id: 10, name: 'Chinmay'},
{id: 27, name: 'Sanjib'},
{id: 35, name: 'Kanhu'},
{id: 38, name: 'Pradeepta'},
{id: 39, name: 'Debsish'},
];
$scope.selectedUserProfile= $scope.userProfiles[1].id;
$scope.existingId = 35;
};
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
Name
<select id="requestorSite" ng-model="selectedUserProfile" ng-options="userProfile.id as userProfile.name for userProfile in userProfiles">
</select>
<br/>
</div>
以下是下拉列表中的5个名字,但我想从我的下拉选项中删除kanhu
。你能告诉我如何删除它吗?
我尝试使用过滤器userProfile.id as userProfile.name for userProfile in userProfiles | filter:{id: !existingId}
这个不起作用。
答案 0 :(得分:1)
使用|过滤器:{id:&#39;!&#39; + existingId}
0
&#13;
var myApp = angular.module('myApp',[]);
function myCtrl ($scope) {
$scope.userProfiles = [
{id: 10, name: 'Chinmay'},
{id: 27, name: 'Sanjib'},
{id: 35, name: 'Kanhu'},
{id: 38, name: 'Pradeepta'},
{id: 39, name: 'Debsish'},
];
$scope.selectedUserProfile= $scope.userProfiles[1].id;
$scope.existingId = 35;
};
&#13;
答案 1 :(得分:1)
<div ng-app="myApp" ng-controller="myCtrl">
Name
<select id="requestorSite" ng-model="selectedUserProfile" ng-options="userProfile.id as userProfile.name for userProfile in userProfiles | filter:'!Kanhu'">
</select>
<br/>
</div>
答案 2 :(得分:1)
为什么要从下拉列表中删除所选的选项,您可以轻松地禁止用户选择该值(有任何特定原因吗?),我会将其保留在下拉列表中,但该选项将处于禁用状态。
<强>标记强>
<select id="requestorSite"
ng-model="selectedUserProfile"
ng-options="userProfile.id as userProfile.name disable when (userProfile.name == 'Kanhu') for userProfile in userProfiles">
</select>
类似answer
答案 3 :(得分:0)
您可以尝试使用以下选项:
希望有帮助=)
this.nChartControl
var myApp = angular.module('myApp',[]);
function myCtrl ($scope) {
$scope.userProfiles = [
{id: 10, name: 'Chinmay'},
{id: 27, name: 'Sanjib'},
{id: 35, name: 'Kanhu'},
{id: 38, name: 'Pradeepta'},
{id: 39, name: 'Debsish'},
];
$scope.selectedUserProfile= $scope.userProfiles[1].id;
$scope.existingId = 35;
};