简体   繁体   English

如何删除这些元素?

[英]How do I remove these elements?

Im new to Angular and Im helping a friend....they have some checkboxes built with '+' and '-'signs to expand collapse. 我是Angular的新手,并且我正在帮助一个朋友。...他们有一些带有'+'和'-'符号的复选框可扩展折叠。 All checkboxes by default have the "+"....I have a JS function that loops through and finds if the node has children or not. 默认情况下,所有复选框都带有“ +”。...我有一个JS函数,该函数循环遍历并查找该节点是否有子节点。 If the length is '0' I want to remove the '+' and the '-' all 如果长度为“ 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 的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 );
    }
}

You would just add the following to the ng-show directive to look at the length of the category.node.length > 0: 您只需将以下内容添加到ng-show指令中,即可查看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>

Pretty much what chubbsondubs said, however, you could simplify the html like so: chubbsondubs几乎说了什么,但是,您可以像这样简化html:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM