如何匹配KeyId,如果keyId将匹配从AngularJS中的数组中删除?

时间:2017-08-08 09:00:47

标签: javascript jquery angularjs



        /**
         * @Summary: setUserAccessB  function, to get detail of the shared product.
         * @param: event, index, userObj
         * @return: callback(response)
         * @Description:
         */
        $scope.buyerObjectList            = [];
        $scope.productDBList              = [];
        $scope.productObjectForShareModal = null;

        $scope.countConnectedBuyer  = 0;
        $scope.setUserAccessB = function(index, isChecked, keyId) {
          if(isChecked) {
            $scope.buyerObjectList.push(keyId);
            $scope.countConnectedBuyer ++;
          } else {
            var index = $scope.buyerObjectList.indexOf(keyId);
            $scope.buyerObjectList.splice(index, 1);
            $scope.countConnectedBuyer --;
          }
        }

            /**
             * @Summary: checkAllConnectedUser function, to create album
             * @param: index, productObj
             * @return: callback(response)
             * @Description:
             */
            $scope.checkAllBuyerKeyId      = [];
            $scope.buyerObj                = [];
            $scope.intermediaryObjectList  = [];
            $scope.checkAllConnectedUser = function(isChecked) {
              if(isChecked) {
                if ($scope.selectedAll) {
                  $scope.selectedAll = false;
                } else {
                  $scope.selectedAll = true;
                }	
                angular.forEach($scope.buyerRelationDtoForModal.buyerDtos, function (buyerObj) {
                  buyerObj.select = $scope.selectedAll;
                  //IF ID WILL BE EXIST IN THE ARRAY NOT PSUH THE KEYID
                  if($scope.buyerObjectList.indexOf(buyerObj.userTypeDto.keyId) == -1) {
                    $scope.buyerObjectList.push(buyerObj.userTypeDto.keyId);
                    $scope.countConnectedBuyer ++;
                  }
                });

               } else {
                  $scope.selectedAll  = false;
                  //USED FOR UNCHECK ALL THE DATA ONE- BY-ONE
                  angular.forEach($scope.buyerRelationDtoForModal.buyerDtos, function (buyerObj) {
                    buyerObj.select = $scope.selectedAll;
                    var index = $scope.buyerObjectList.indexOf(buyerObj.userTypeDto.keyId);
                    $scope.buyerObjectList.splice(index, 1);
                    if($scope.buyerObjectList.length == 0) {
                      $scope.countConnectedBuyer = 0;
                    } else {
                      $scope.countConnectedBuyer --;
                    }
                  });
                }
             }

<div id="buyer" class="w3-container userSection">
  <div class="checkbox w3-margin" ng-if="buyerRelationDtoForModal.buyerDtos.length > 0">
      <label>
        <input type="checkbox" ng-model="selectedAll"  ngclick="checkAllConnectedUser(selectedAll)"/>Check All
      </label>
      <span class="w3-right" ng-if="countConnectedBuyer">
        <h5>You are selecting {{countConnectedBuyer}} buyers!</h5>
      </span>
    </div>
      <div class="w3-row userObjRow" ng-repeat="buyerObj in buyerListTemp = (buyerRelationDtoForModal.buyerDtos) track by $index" 
        ng-if="checkIfBuyerIsSharedAlready(buyerObj.keyId) && buyerObj.userAccessType == 'private'">
        <div class="col-md-10 col-sm-10 productDetailsWrap item_info" >
          <div class="w3-row ng-cloak">
            <div class="checkbox">
              <label id="shareUserSection">
                <input type="checkbox" ng-model="buyerObj.select" 
                  ng-click ="setUserAccessB($index, buyerObj.select, buyerObj.userTypeDto.keyId)"/>
                  <i class="glyphicon glyphicon-user w3-text-black"></i>
                    {{buyerObj.personName}} 
                  <span class="w3-text-teal">
                    {{buyerObj.userTypeDto.userTypeAddressDtos[0].city}}
                  </span>  
              </label> -&nbsp; 
              <span class="w3-tag w3-teal w3-round w3-small">
                &nbsp;{{buyerObj.userTypeDto.userType}}
              </span>
            </div>
          </div>
        </div>
       </div>
&#13;
&#13;
&#13;

我必须与用户共享产品,我必须列出 - 与用户共享产品的第一个连接用户列表,第二个是共享用户列表(共享产品列表)如果我点击这里的全部复选复选框所有复选框将检查,但我必须一次删除1个用户,然后单击共享用户列表。再次点击这里的全部复选复选框只有1个用户找到,我将获得1个更新用户但在这里我将被发现所有用户再次,因为我再次迭代所有列表, angular.forEach($ scope.buyerRelationDtoForModal.buyerDtos) - 在这里我将删除匹配的keyID并更新1个用户如何解决此问题?

0 个答案:

没有答案