gpt4 book ai didi

angularjs - 删除基于 Angular js 中的按钮单击的选择选项

转载 作者:行者123 更新时间:2023-12-04 21:07:57 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个选择 html,它具有以下选项
“添加”、“删除”、“复制”、“成员复制”

上面的下拉页面对于添加和编辑屏幕都是通用的。到目前为止,如果我们来自任何添加单击或编辑单击下拉菜单,则具有所有选项。 (注意:加载页面本身时下拉绑定(bind)。我们将根据点击显示/隐藏)

根据新要求,我需要删除除“添加”之外的所有其他选项,此外单击并在编辑单击中删除“添加”选项。

选择html:

<select name="ReasonID" required ng-model="member.ReasonID" class="form-control" ng-options="reason.ID as reason.Description for reason in reasons |orderBy: reason.Description"></select>

JS
$scope.manageMember = function (member) {
$scope.showGrid = false;
$scope.showForm = true;
reset();
$scope.memberTemp = member;
angular.extend($scope.member, member); };

如果您需要更多详细信息,请告诉我。

最佳答案

更新:

这里是完整的示例代码和带有虚拟数据的工作演示。

HTML

<div ng-app>
<h2>Todo</h2>
<div ng-controller="TodoCtrl">
<select name="ReasonID" required ng-model="member.ReasonID" class="form-control" ng-options="reason.ID as reason.Description for reason in reasons |orderBy: reason.Description"></select>
<br/>
<input type="button" ng-click="manageMember(undefined)" value="add"/>
<input type="button" ng-click="manageMember('bla bla bla')" value="edit"/>
</div>
</div>

JS
function TodoCtrl($scope) {
$scope.reasons = [{ID:1,Description :"Addition"}, {ID:2,Description :"Deletion"},{ID:3,Description :"Duplicate"},{ID:4,Description :"Member Duplicate"}];

var reasonsTemp =angular.copy($scope.reasons);

$scope.manageMember = function (member) {
console.log(reasonsTemp)
$scope.reasons=reasonsTemp;// assign global object to model
$scope.showGrid = false;
$scope.showForm = true;
$scope.memberTemp = member;
var EditArray=[];
for(var i = 0 ; $scope.reasons.length>i;i++)
{
if($scope.reasons[i].Description === ($scope.memberTemp == undefined ? "Addition" : "bla bla bla"))// condition for is this addition or not
{
EditArray = $scope.reasons[i];
break;
}
else // if is it not addition, then addition only offect that object. because we were already assigned original value globally
{
if($scope.reasons[i].Description!=="Addition")
{
EditArray.push($scope.reasons[i])
}
}
}
$scope.reasons=EditArray;
console.log($scope.reasons);
}
}

Working Demo On console window

关于angularjs - 删除基于 Angular js 中的按钮单击的选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41217869/

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