2014-09-04 57 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)" 
相關問題