2014-07-21 89 views
0

Im新增Angular和Im幫助朋友....他們有一些用'+'和' - '標記構建的複選框來展開摺疊。默認情況下,所有複選框都有「+」....我有一個JS函數,它循環查找節點是否有子節點。如果長度爲「0」我想刪除的「+」和「 - 」所有如何刪除這些元素?

<div ng-repeat="category in list> 
    <a href="" ng-show="!dList" ng-click="depList=!depList">+</a> 
    <a href="" ng-show="dList" ng-click="depList=!depList">-</a> 
    <a href="" ng-click="dList=!depList"></a>  
    <input type="checkbox" ng-checked="category['@attributes'].isChecked" ng-click="toggleCheckBox1(this,1)"> 
</div> 

的JavaScript

var eObject= $scope.List; 
for(var m = 0; m < eObject.length; m++){ 
    if(eObject[m].node.length == 0){ 
     //REMOVE + OR - SIGN HERE!! 
    } else{ 
     eObject[m].node.length); 
    } 
} 

回答

0

你只添加以下到NG-顯示指令看category.node.length> 0的長度:

<div ng-repeat="category in list> 
<a href="" ng-show="!dList && category.node.length > 0" ng-click="depList=!depList">+</a> 
<a href="" ng-show="dList && category.node.length > 0" ng-click="depList=!depList">-</a> 
<a href="" ng-click="dList=!depList"></a>  
<input type="checkbox" ng-checked="category['@attributes'].isChecked" ng-click="toggleCheckBox1(this,1)"> 
</div> 
0

差不多chubbsondubs說什麼,但是,你可以簡化像這樣的HTML:

<div ng-repeat="category in list"> 
    <div ng-show="category.node.length"> 
     <button>+</button> 
     <button>-</button> 
    </div> 
    <input type="checkbox" etc> 
</div>