2016-05-17 45 views
0

隐藏表,如果所有的数据字段 - TD与多个跨度值为空

$scope.hide_emptytable() = function{ 
 
if ($.trim($('.acf-dynamic-table .field').text())=="") { 
 
    $('.acf-dynamic-table').hide(); 
 
} 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> 
 
<div ng-repeat="t in[]"> 
 
<table class="acf-dynamic-table"> 
 
<tr> 
 
<td>Name</td> 
 
<td>Address</td> 
 
</tr> 
 
<tr> 
 
<td class="field">t.name</td> 
 
<td class="field"><span>t.ward_no</span> <span>t.street</span> <span>t.city</span> <span>t.state</span> <span>t.postcode</span></td> 
 
</tr> 
 
</table> 
 
</div> 
 

 
<div ng-repeat="t in []"> 
 
<table class="acf-dynamic-table"> 
 
<tr> 
 
<td>Name</td> 
 
<td>Address</td> 
 
</tr> 
 
<tr> 
 
<td class="field"></td> 
 
<td class="field"><span></span> <span></span> <span></span> <span></span> <span></span></td> 
 
</tr> 
 
</table> 
 
</div> 
 
<span style="display : none">{{hide_emptytable()}}</span>

我想隐藏的表,如果与类字段列的值是空的。例如第二个表应该隐藏,但它不工作。 对于地址,值在它们之间的一个空间范围内。

+0

不知道,如果你的问题其原因,但:'= {功能'是你没有的参数列表,比如'功能(语法错误){' –

回答

0

我会更改hideempty表来返回一个布尔值并在表上使用ng-if =“hide_emptytable”。

$scope.hide_emptytable() = function{ 
    return ($.trim($('.acf-dynamic-table .field').text())=="") 
} 
0

正确的代码应该是

$scope.hide_emptytable = function(){ 
    return $.trim($('.acf-dynamic-table .field').text()) == "";  
} 

那么你应该使用ng-show

ng-show = hide_emptytable() 

咨询你不要混合使用angularjs.Angularjs jQuery使用MVVM模式,你可以充分利用角功能来实现你想要的而不是写作hide()

0

你可以用这段代码解决你的问题。

$(function(){ 
 
    $('.acf-dynamic-table .field') 
 
    .has('span') 
 
    .each(function(){ 
 
    if($(this).children().not(':empty').length == 0) 
 
     $(this).parents('table').hide(); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
 
<div id='print'></div> 
 
<div ng-repeat="t in[]"> 
 
    <table id='1' class="acf-dynamic-table"> 
 
    <tr> 
 
     <td>Name1</td> 
 
     <td>Address1</td> 
 
    </tr> 
 
    <tr> 
 
     <td class="field">t.name</td> 
 
     <td class="field"><span>t.ward_no</span> <span>t.street</span> <span>t.city</span> <span>t.state</span> <span>t.postcode</span></td> 
 
    </tr> 
 
    </table> 
 
</div> 
 

 
<div ng-repeat="t in []"> 
 
    <table id='2' class="acf-dynamic-table"> 
 
    <tr> 
 
     <td>Name2</td> 
 
     <td>Address2</td> 
 
    </tr> 
 
    <tr> 
 
     <td class="field"></td> 
 
     <td class="field"><span></span> <span></span> <span></span> <span></span> <span></span></td> 
 
    </tr> 
 
    </table> 
 
</div>