我正在使用 openTemplate 函数在#TreeDiv 中渲染一个动态树树视图。在为 dynatree 中的某个模板加载所有单元之前,我清空/清除 #TreeDiv 以删除现有树。这是第一次。
当我尝试在#TreeDiv 中为另一个模板加载其他单位时,我看不到我的单位数据,div 只是空的。不知何故,#TreeDiv 被破坏了,因为代码像第一次创建单元树一样正常运行。不同之处在于,在我第二次执行 .empty() 时,已经存在一棵树。
我错了什么?
function openTemplate(dlg, form) {
$.ajax({
url: $(form).attr('action'),
type: 'POST',
data: form.serialize(),
success: function (response) {
if (response.success) {
dlg.dialog("close");
$('#TreeDiv').empty();
loadUnits(response.data);
}
else {
// Reload the dialog with the form to show model/validation errors
dlg.html(response);
}
}
});
}
function loadUnits(data) {
$('#TreeDiv').dynatree({
onActivate: function (node) {
getTestSteps(node.data.key);
},
onLazyRead: function (node) {
node.appendAjax({
url: '@Url.Action("GetChildrenUnits","Unit")',
data: {"unitId": node.data.key, "templateId": 1 }
});
},
children: data
});
}