加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 根据角度js中的按钮单击删除选择选项

发布时间:2020-12-17 07:15:24 所属栏目:安全 来源:网络整理
导读:在我的应用程序中,我有一个选择html有以下选项 “添加”,“删除”,“重复”,“成员重复” 上面的下拉页面对于添加和编辑屏幕都很常见.截至目前,如果我们来自任何添加点击或编辑点击下拉列表有所有选项. (注意:下载页面在加载页面本身时绑定.我们将根据点击
在我的应用程序中,我有一个选择html有以下选项
“添加”,“删除”,“重复”,“成员重复”

上面的下拉页面对于添加和编辑屏幕都很常见.截至目前,如果我们来自任何添加点击或编辑点击下拉列表有所有选项. (注意:下载页面在加载页面本身时绑定.我们将根据点击显示/隐藏)

根据新要求,我需要删除除“添加”之外的所有其他选项,然后点击并删除编辑点击中的“添加”选项.

选择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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读