2014-09-04 58 views
0

嗨请帮我我新角js我的li范围不能在角js中删除为什么?

我只是创建一个函数。 我重复了这个内容。 我创建了一个功能,添加下一个选项卡部分并删除此部分。 我创建一个相同的功能,以另一个标签添加prev选项卡部分并删除此部分。

但我只有数据复制这个功能不删除数据,不显示。

请帮我

我的代码是这样的

HTML代码

<body ng-app="taskPanel"> 
    <div class="" ng-controller="TasksController"> 
    <tabset panel-tabs="true" panel-class="panel-inverse"> 
     <tab> 
         <tab> 
          <tab-heading> <span class="hidden-xs">ACTIVE</span> <span class="badge badge-primary">{{tasksComplete.length}}</span></tab-heading> 
          <div class="tasklist"> 
           <ol class="panel-tasks"> 
            <li ng-repeat="item in tasksComplete"> 
             <a href="#" class="preview-question"> 
              <i class="fa fa-eye">eye</i> 
             </a> 
             <label> 
              <span class="task-description">{{item.title}}</span> 
              <span class="label label-{{item.color || 'primary'}}" ng-show="item.label">{{item.label}}</span> 
              <div class="more-icn"> 
               <div class="pull-left"> 
                <button class="active-check" ng-click="pushActive(this, item)">Push to InActive Tab</button> 
               </div> 

              </div> 
             </label> 
            </li> 
           </ol> 
          </div> 
         </tab> 
         <tab> 
          <tab-heading> <span class="hidden-xs">InACTIVE</span> <span class="badge badge-primary">{{tasksComplete.length}}</span></tab-heading> 
          <div class="tasklist"> 
           <ol class="panel-tasks"> 
            <li ng-repeat="item in tasksInComplete"> 
             <a href="#" class="preview-question"> 
              <i class="fa fa-eye"></i> 
             </a> 
             <label> 
              <span class="task-description">{{item.title}}</span> 
              <span class="label label-{{item.color || 'primary'}}" ng-show="item.label">{{item.label}}</span> 
              <div class="more-icn"> 
               <div class="pull-left"> 
                <button class="active-check" ng-click="pushInActive(this, item)">Push To Active Tab</button> 
               </div> 

              </div> 
             </label> 
            </li> 
           </ol> 
          </div> 
         </tab> 

    </tabset> 

    </div> 
    </body> 

角的js代码是

//代码放在这里

var appan = angular.module('taskPanel', []); 
appan.controller('TasksController', ['$scope', function($scope){ 
    $scope.tasksComplete = [ 
     { title: "I m first" }, 
     { title: "I m Second" }, 
     { title: "I m thrid" } 
    ]; 


    $scope.tasksInComplete = [ 
     {title: "i m incompletred 1"}, 
     {title: "i m incompletred 2"}, 
     {title: "i m incompletred 3"} 
     ]; 


     $scope.remove = function(scope){ 
     scope.remove(); 
     }; 


     $scope.pushActive = function(scope, item){ 
     $scope.tasksInComplete.push(item); 
     scope.remove(); 
     }; 

     $scope.pushInActive = function(scope, item){ 
     $scope.tasksComplete.push(item); 
     scope.remove(); 
     }; 

}]); 

Live Demo

回答

1

试试这个,使用$指数删除数组元素

$scope.pushActive = function(index, item){ 
    $scope.tasksComplete.splice(index, 1); 
    $scope.tasksInComplete.push(item); 

    }; 

    $scope.pushInActive = function(index, item){ 
    $scope.tasksInComplete.splice(index, 1); 
    $scope.tasksComplete.push(item); 

    }; 

plunker

http://plnkr.co/edit/fp3gcf9PlBi9XnpNYFZQ?p=preview

+0

HI @Kaken我可以延迟到这个功能我想我点击在标签有些需要3秒左右的时间比移动到下一个标签 – 2014-09-04 08:10:41

+0

嗨@RohitAzad尝试使用$超时服务。像http://plnkr.co/edit/aB1XNuaAqe52iSAjRLXl?p=preview – Kaken 2014-09-04 08:54:15

1

我定你的代码,你可以看到它here

措辞让我心烦意乱。一旦我改变了查看措辞以匹配控制器的措词,那就很好。

var appan = angular.module('taskPanel', []); 
appan.controller('TasksController', ['$scope', function($scope){ 
    $scope.tasksInActive = [ 
    { title: "I m first" }, 
    { title: "I m Second" }, 
    { title: "I m thrid" } 
    ]; 

    $scope.tasksActive = [ 
    {title: "i m incompletred 1"}, 
    {title: "i m incompletred 2"}, 
    {title: "i m incompletred 3"} 
    ]; 

    $scope.pushActive = function(scope, item){ 
    $scope.tasksInActive = removeItemFromList(item, $scope.tasksInActive); 
    $scope.tasksActive.push(item); 
    }; 

    $scope.pushInActive = function(scope, item){ 
    $scope.tasksActive = removeItemFromList(item, $scope.tasksActive); 
    $scope.tasksInActive.push(item); 
    }; 

    function removeItemFromList(item, list){ 
    return list.filter(function(i){ 
     return i != item; 
    }); 
    } 
}]); 
+1

我认为这是更有效的未使用的功能removeItemFromList 随着$指数和拼接的方法是所有需要 – Kaken 2014-09-04 07:18:10

2

你可以使用这样approatch:

控制器:

$scope.tasksComplete = [ 
    { title: "I m first"}, 
    { title: "I m Second"}, 
    { title: "I m thrid"} 
]; 

$scope.pushActive = function(item) { 
    $scope.tasksComplete.splice(item,1); 
}; 

教职员

ng-click="pushActive($index)" 
相关问题