Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取行';在ng中重复索引(或id)以对特定行执行某些操作_Javascript_Angularjs - Fatal编程技术网

Javascript 获取行';在ng中重复索引(或id)以对特定行执行某些操作

Javascript 获取行';在ng中重复索引(或id)以对特定行执行某些操作,javascript,angularjs,Javascript,Angularjs,我是angular方面的新手,我想获取特定行的索引以在其上执行函数hidestuff(),我将item.id传递给函数,我想隐藏包含此id的行。。但是如何传递行索引来删除整行呢 html: 您可以使用$index。有关详细信息,请阅读以下内容: 我认为你应该这样做: <tr id="tr-{{item.id}}" ng-repeat="item in ItemsByPage[currentPage]"> <td&

我是angular方面的新手,我想获取特定行的索引以在其上执行函数
hidestuff()
,我将
item.id
传递给函数,我想隐藏包含此id的行。。但是如何传递行索引来删除整行呢

html:


您可以使用$index。有关详细信息,请阅读以下内容:

我认为你应该这样做:

            <tr id="tr-{{item.id}}" ng-repeat="item in ItemsByPage[currentPage]">
                    <td>
                      <div> 
                           {{item.id}} 
                      </div>                                
                    </td>
                    <td>
                       <div editable-text="item.name" 
                            onaftersave='inlineupdateName(item.id,item.name)' 
                            ng-model="tname" data-n='item.name'>

                            {{item.name}}
                       </div>
                    </td>
                    <td>
                       <div editable-text="item.phone" 
                             onaftersave='inlineupdatephone(item.id,item.phone)'
                             ng-model="tphone">
                             {{item.phone}}
                        </div> 
                    </td>
                </tr>

             <input  type="text" ng-model="delId"   class="form-control" 
                     placeholder="Enter user id to delete th user">                        
            <button ng-click="deleteuser(delId)"  type="button" 
                    class="btn btn-primary">

                    Delete User
            </button> 

您可以使用$index获取索引。请参阅文档@Overmachine i read,但是如何获取与控制器中函数中的
delId
相匹配的索引如何将其与
$scope.hideStuff=function(delId)一起使用{$scope.startFade=true;//这里我想使用索引删除行$scope.hidden=true;};
thanx somuch@hey您不需要$scope.hidden=true;只需使用$(“tr-”+delId).hide();请尝试此方法修改为使用
{{item.id}
作为
@HalaElBarchah的id,请阅读此答案,看看是否足以标记为正确。它不起作用,我想隐藏具有用户id=
delId
的行。那么如何传递并使用输入的
delId
和行索引来删除此行?
$scope.hideStuff = function (delId) {
                $scope.startFade = true;
                 //here i want to use the index to delete the row
                $scope.hidden = true;
            };
            $scope.deleteuser = function (dalId) {                   
                var data = {delId : $scope.delId};
                $http.post('delete.php', data )
                  .success(function(response) {
                    $scope.hideStuff(delId);
                  });  

            };
            <tr id="tr-{{item.id}}" ng-repeat="item in ItemsByPage[currentPage]">
                    <td>
                      <div> 
                           {{item.id}} 
                      </div>                                
                    </td>
                    <td>
                       <div editable-text="item.name" 
                            onaftersave='inlineupdateName(item.id,item.name)' 
                            ng-model="tname" data-n='item.name'>

                            {{item.name}}
                       </div>
                    </td>
                    <td>
                       <div editable-text="item.phone" 
                             onaftersave='inlineupdatephone(item.id,item.phone)'
                             ng-model="tphone">
                             {{item.phone}}
                        </div> 
                    </td>
                </tr>

             <input  type="text" ng-model="delId"   class="form-control" 
                     placeholder="Enter user id to delete th user">                        
            <button ng-click="deleteuser(delId)"  type="button" 
                    class="btn btn-primary">

                    Delete User
            </button> 
        $scope.hideStuff = function (delId) { 
            $("#tr-"+delId).hide();
            //the entire tr (line table) will be hidden.
            // you don't need those $scope variables to hide the elements
        };
        $scope.deleteuser = function (dalId) {                   
            var data = {delId : $scope.delId};
            $http.post('delete.php', data )
              .success(function(response) {
                $scope.hideStuff(delId);
              });  

        };