运行时,我尝试在父节点下添加子节点。当我点击树枝。我调用ajax文件,它有子列表的返回列表结构,我在父节点下设置,但设计不正确。找到我的树形结构图像
$(document).on('click', '.jstree-ocl', function() {
var ContactId = $(this).closest('.clsTwoLevel').attr('id');
var GroupId = $('#cboGroupName').val();
if (ContactId != undefined) {
$.ajax({
url: 'contact-group-treeview.php',
data: 'ContactId=' + ContactId + '&GroupId=' + GroupId,
type: 'POST',
success: function(response) {
$("#MoreThanTwoLevel_"+ContactId).html(response);
}
});
}
});
<div id="jstree">
<?php
while ($row = sqlsrv_fetch_array($GetLevelOneTwo, SQLSRV_FETCH_ASSOC)) {
?>
<ul>
<li>
<?php echo $row['Name'] . ' (' . $row['TotalCount'] . ')'; ?>
<?php
if ($row['TotalCount'] != 0) {
$GetLevelTewoName = get_level_tewo_name($conn, $GroupId, $row['ContactId']);
while ($row_level_two = sqlsrv_fetch_array($GetLevelTewoName, SQLSRV_FETCH_ASSOC)) {
?>
<ul>
<li class="clsTwoLevel" id="<?php echo $row_level_two['ContactId']; ?>">
<?php echo $row_level_two['Name'] . ' (' . $row_level_two['TotalCount'] . ')' ?>
<?php if ($row_level_two['TotalCount'] != 0) { ?>
<ul>
<!--<div class="MoreThanTwoLevel"></div>-->
<li class="MoreThanTwoLevel"></li>
</ul>
<?php } ?>
</li>
</ul>
<?php } ?>
<?php } ?>
</li>
</ul>
<?php } ?>
ajax结果
<ul>
<li class="clsTwoLevel jstree-open" id="4710">Kalpnaben Jitendrabhai Soni (1)
</li>
</ul>
<ul>
<li class="clsTwoLevel jstree-open" id="19">
Ghanshyambhai Kalubhai Patel (3)
<ul>
<li class="MoreThanTwoLevel" id="MoreThanTwoLevel_19"></li>
</ul>
</li>
</ul>
<ul>
<li class="clsTwoLevel jstree-open" id="4711">Mitaben Ghanshyambhai Patel (1)
</li>
</ul>