Javascript 如何显示父节点的展开图标?
如果一个td类值是'indent0',下一个td类值是'indent1','indent2',我需要在上面两个'td'之间显示一个展开图标; 其中,indent0-表示父节点,indent1-子节点,indent2-大子节点Javascript 如何显示父节点的展开图标?,javascript,jquery,html,Javascript,Jquery,Html,如果一个td类值是'indent0',下一个td类值是'indent1','indent2',我需要在上面两个'td'之间显示一个展开图标; 其中,indent0-表示父节点,indent1-子节点,indent2-大子节点 <div class="panel panel-default"> <div class="table-responsive">
<div class="panel panel-default">
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tbody>
<? foreach ( $aspects as $a ) {?>
<tr class="js-data-selector"
data-taxonomy-id="<?=$a['taxonomy_id']?>">
<td width="0.5">
<?draw_note_icon (); ?>
</td> <td class="indent<?=$a['indent']?>">
<?=$a['aspect_label']?>: <span class="aspect-data" data-taxonomy-id="<?=$a['taxonomy_id']?>"></span></td>
</tr>
<?}?>
</tbody>
</table>
</div>
</div>
Example
A - indent0
B - indent0
C - indent1
D - indent1
E - indent0
F - indent1
G - indent2
:我想您可以在呈现数据时对其进行操作。不需要使用jQuery。你可以试试看。虽然它是非常严格的代码。你可以让它更一般化
function draw_note_icon($i) {
global $aspects;
$curr = $aspects[$i]['indent'];
$nxt = isset($aspects[$i+1]['indent'])?$aspects[$i+1]['indent']:null;
if(!is_null($nxt)) {
if(in_array($nxt, array(2,1))) {
if(($nxt == 2) || ($nxt == 1 && $curr != 1))
echo '+';
}
}
}
您可以使用for循环而不是foreach来获取和检查是否存在child。
function draw_note_icon($i) {
global $aspects;
$curr = $aspects[$i]['indent'];
$nxt = isset($aspects[$i+1]['indent'])?$aspects[$i+1]['indent']:null;
if(!is_null($nxt)) {
if(in_array($nxt, array(2,1))) {
if(($nxt == 2) || ($nxt == 1 && $curr != 1))
echo '+';
}
}
}